Regular Expression for getting everything after last slash [duplicate]
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
In original question, just a backslash
is needed before slash
, in this case regex will get everything after last slash
in the string
([^\/]+$)
No, an ^
inside []
means negation.
[/]
stands for 'any character in set [/]'.
[^/]
stands for 'any character not in set [/]'.