Tuesday, 17 January 2017

regex - Regular Expression for getting everything after last slash




I was browsing stackoverflow and have noticed a regular expression for matching everything after last slash is



([^/]+$)


So for example if you have http://www.blah.com/blah/test
The reg expression will extract 'test' without single quotes.



My question is why does it do it? Doesn't ^/ mean beginning of a slash?




EDIT:
I guess I do not understand how +$ grabs "test". + repeats the previous item once or more so it ignores all data between all the / slashes. how does then $ extract the test


Answer



No, an ^ inside [] means negation.



[/] stands for 'any character in set [/]'.



[^/] stands for 'any character not in set [/]'.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...