Reputation: 83
I have two links:
1: /aaa/bbbb/ccccc.htm
2: /xxx/yyy.htm
What regex is able to match the second link?
I have tried:
^\/.*\/.*[^\/].*
But, it match all of them.
Upvotes: 2
Views: 2377
Reputation: 27723
I'm guessing that we might want to pass both URLs, which in that case we would start with:
(\/[a-z]+)?(?:\.htm)?
We can then add more boundaries, if you wish.
If this wasn't your desired expression, you can modify/change your expressions in regex101.com.
jex.im visualizes regular expressions:
const regex = /((\/[a-z]+)?(?:\.htm)?)/gm;
const str = `/aaa/bbbb/ccccc.htm
/xxx/yyy.htm`;
const subst = `Group #1: $1\nGroup #2: $2\n`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
If you only wish to pass the second URL and fail the first one, you can simply add some boundaries to your expression, maybe something similar to this would work:
^\/[a-z]+\/[a-z]+.htm$
Upvotes: 3