Regex to match file and version number
I am having trouble getting the following regex to work
It will only grab the file name not file name and version of:
I only get “bubba” back
I can add the eol character $ and get all but the last line which may not have a CRLF. I need to be able to match this type of string.
What am I doing wrong?
Appreciated your time looking at this.
The regex \w+.*? seems quite wide - it will match “any set of one or more word characters (equal to [a-zA-Z0-9_]”
Without it, it will only run the match once, stopping after matching bubba
Also, the ? makes the + lazy, so it will only match as little as needed - remove the ?
(it should be returning the file name and version now and, depending on the text being matched, a lot of other stuff)
A white space character (e.g. /\w+\s./g ) or space (/\w+\x20./g) character after \w would also limit the matches.
An end anchor $ does not require CRLF. In fact /\w+\x20.$/g would only match the last line with the file name and version.
Add a multi-line switch (e.g. /\w+\x20.$/gm) if there is only one match per line
Finally, we probably need to limit .* to match only numbers and periods
When I run document.body.innerText.match(/\w+\x20[0-9.]+$/gm) against this page in the console I get
(2) [“bubba 1.2.11”, “POSTS 66”]