How to get the certain segment of a URL using regex? -
say url http://aa/bb/cc
. "aa" in segment 1, "bb" in 2 , "cc" in 3. how regex extract given number of segment? (so \2
, \3
refers part of url.)
try regex:
http:/(?:/([^/]+))+
explaination:
(subexpression)
captures matched subexpression , assigns zero-based ordinal number.
(?:subexpression)
defines noncapturing group.
+
matches previous element 1 or more times.
[^character_group]
negation: matches single character not incharacter_group
.
Comments
Post a Comment