need help to create regular expression matching string
www.*.abc.*/somestring
Here * is wild card it can be anyhing like us, uk
or com, edu
like
www.us.abc.com/somestring
www.uk.abc.edu/somestring
need help to create regular expression matching string
www.*.abc.*/somestring
Here * is wild card it can be anyhing like us, uk
or com, edu
like
www.us.abc.com/somestring
www.uk.abc.edu/somestring
www\.([a-z]{2})\.abc\.(com|edu)/(.+)
You can then extends this regex to include other valid generic top-level domain name (net, org, ...)
www\.([a-z]{2})\.abc\.(com|edu|org|net)/(.+)
You will get the Country code top-level domain in the group number 1, the top-level domain in group 2.
If it's a URL, it can match any a-z
character, or 0-9
, or a dash (-
). Each component has at least one character, so use +
as the multiplier. Currently, tlds are only a-z, but this regex is a bit more robust (you never know!):
/www\.[-a-z0-9]+?\.abc\.[-a-z0-9]+?\/somestring/
It assumes nothing about the length of each component, and that it's all lowercase.
Put [^.]+
instead of asterisks and \.
instead of dots, and you'll be done.
www\.[^.]+\.abc\.[^.]+/somestring
[^.]
matches any non-dot, [^.]+
matches a string of nondots with at least one character. \.
matches a dot, because .
matches any character.
Try the following regular expression:
^www\.\w+\.abc\.\w+\/\w+$
Something like that:
www\.\w+\.abc\.\w+\/somestring
I do recommend to use this Online RegEx builder to learn how it works