Regex - Looking for a number either at the BOL or EOL but also not embed in other numbers or text -


this question has answer here:

i want find '106'. can't in longer number 21067 nor can in text string y106m. want find if @ beginning, or end of line, or if line.

so these lines out:

106m 1106 106in string bad if starts line , may finish target not tail of string106 

but these in:

106 else 106 , of couse "106' work want 106 show not embedded in other numbers or text it's ok end of line 106 106 may start line 

i have tried following search string , many variations of it:

(^|[^0-9a-za-z])106($|[^0-9a-za-z])

i'm new-ish regex, , don't have handle on how anchor characters work.

you can use \b word boundary assertion:

\b106\b 

demo

or more specific lookarounds:

(?<=^|\w)106(?=$|\w) 

demo

or, pointed out in comments, (?<!\w)106(?!\w) works too. or (?<=[^a-za-z0-9])106(?=[^a-za-z0-9]) work better since _ included in \w , \w set of characters.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -