javascript - Why is non-greedy character not acting 'non-greedy'? -
I am working with a regex in javascript.
I have this regex: and this string: I hope to get the Regular expression will always try to match from left to right even if You have a few options to fix this: /
/ path / to / file
/ file as a result, but instead getting the whole string back. What do I not understand here?
? should be made of
+ non-greedy, which means it will match some of the most possible characters.
. +? is non-greedy, however, if possible it will try to match the beginning of the string and will only advance the situation in the event of failure of the match.
/.* (\ /. +?) $ / , and then you get the first code as the group's content as
/ File will be
. +? could not match any of the additional
/ , so it should be
/ \ / [^ \ /] + $ / .
Comments
Post a Comment