I'm facing a problem with Regex... I had to match sharepoint URL.. I need to match the "shortest"
Something like:
http://aaaaaa/sites/aaaa/aaaaaa/
m = Regex.Match(URL, ".+/sites/.+/");
m.Value equals to the whole string...
How can I make it match
http://aaaaaaa/sites/aaaa/
and nothing else??
Thank you very much!
.+
is greedy, so it will match as many characters as possible before stopping. Change it to .+?
and the match will end as soon as possible:
m = Regex.Match(URL, ".+/sites/.+?/");
Try making the regex matching everything but a /
instead of simply everything. This is done by using the not form of the character class atom [^]
.
m = Regex.Match(URL, ".+/sites/[^/]+/");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With