Answer the question
In order to leave comments, you need to log in
How to choose a regular expression for url?
I have a url for which the regular expression should work.
Url like - mysite.com/param/sometext-alt-text/otherparam/text?...
Regular match should work on /param/ and /otherparam/
Help me choose a regular match. Thank you)
Answer the question
In order to leave comments, you need to log in
So?
const links = [
'mysite.com/param/sometext-alt-text/otherparam/text?zzzz',
'mysite.com/param/foo/otherparam/qqqqqq',
'mysite.com/param/123/otherparam/jfghjfghk?...',
'mysite.com/param/foo/otherparam/gdfsghdfhkj',
'mysite.com/param1/sometext-alt-text/otherparam/text?zzzz',
'mysite.com/param2/foo/otherparam/qqqqqq',
'mysite.com/param/123/otherparam3/jfghjfghk?...',
'mysite.com/param/foo/otherparam4/gdfsghdfhkj',
];
const re = /param\/(?<param>.+)\/otherparam\/(?<otherparam>.*)/;
links.forEach(link => {
const found = link.match(re);
console.log(link, found);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question