Correct syntax to cut absolute url to relative url inside a widget

Hi all, need you help to find out a correct syntax to transform an item, containing absolute URL into relative URL - extracting only relative path part.
I’ve found out on W3Schools that replace(/(^https?\:\/\/[^:\/?#]*(?:\:[0-9]+))?([\/][^?#]*)/, "$2") is the correct syntax for Javascript, but I’ve failed to use this code inside a widget like this: url: =items[props.camerajpeg].state.replace(/(^https?\:\/\/[^:\/?#]*(?:\:[0-9]+))?([\/][^?#]*)/, "$2").
What am I missing? Are there other ways to achieve my goal? Like url.pathname.

The widget expressions do not use full javascript, only a limited js-like expression parser. I do not believe that it accepts regex at all.

Because of the limitations of the expression parser, you often have to get very creative with string manipulation. Without knowing more about the actual url(s) you are trying to trim, I can only offer general suggestions: you might be able to use split() to divide up the url and then only recombine the portions you want, if the part of the url you are stripping off is consistent you might just be able to directly extract the relevant substring, if the url is coming from an item state, you might be able to apply the transform to the item itself (in which case regex would work) and not have to worry about any conversion in the widget code.

Understood, thank you. I can, of course, transform the item, or change the binding itself to generate relative URL instead of absolute, I was just hoping to find out a universal solution for everyone who could need the same.
Split like url: =items[props.camerajpeg].state.split(/https?\:\/\/[^:\/?#]*(?:\:[0-9]+)/)[1] is not working too.
Why I was hoping to find out a solution - is because the browser’s console seemed to just not like all those backslashes, so I thought there is some syntax mistake.
Maybe URL.pathname could be parsed by browser?

Still using the regex so it’s not going to work. You’re going to have to split using a string literal. I was thinking you might be able to .split("/") and then recombine the relevant parts with `.join(“/”). This still won’t be as easy as it sounds as making a general expression for reducing the the split array is sill going to be just on the edge of what you can do with the expression parser if it’s possible at all.

It’s not the browser’s javascript engine that’s doing the parsing. It’s the expresion parser embedded in the MainUI.

Of course I’ve splitted and recombined, but it’s so ugly looking and isn’t universal that I’m feeling myself sad every time I see the widget =)

url: ="/"+items[props.camerajpeg].state.split('/')[3]+"/"+items[props.camerajpeg].state.split('/')[4]+"/"+items[props.camerajpeg].state.split('/')[5]