I have a string like so:
https://test/api/files/123/versions/1/watermark_content=123456
And I would like to separate this into:
https://test/api/files/123/versions/1/
and
watermark_content=123456
How can I achieve this using regular expressions? Or is there an even better/simpler way to do this without regular expressions?
>Solution :
This splits the two parts:
const href = 'https://test/api/files/123/versions/1/watermark_content=123456';
const matches = href.match(/^((?![/]watermark_content=.*).*[/])(watermark_content=[^/]*)/);
console.log(matches[1]);
console.log(matches[2]);
I’m assuming the "right side" (matches[2]) should be a path node that starts with "watermark_content=".
^((?![/]watermark_content=.*).*[/]) matches everything that doesn’t have "watermark_content=…". And should end with a "/".
(watermark_content=[^/]*) matches "watermark_content=" and everything next to it until a "/" (excluding it, and that doesn’t mean "/" should exist).