Regex matches a line ending with a line or nothing

I want to match strings ending with javascript characters (% 20,% u200E, etc.) or the end of the line.

I have this regex: (/\w*?)*(?=(%\w{2,}|[\s/]))which matches the parts /textin these:

/ text
/ Text
/ Text% 20
/ Text% u200E

But this can not be compared: /text(the character does not end, even a new line)

+4
source share
1 answer

Change the regex to:

/(?:\/\w*)*(?=(?:%\w{2,})|[\s/]|$)/;

Since you do not have a new line \nat the end of your entries. Only the end of the input anchor $will complete the task.

+5
source

All Articles