php - preg_match to check "if reach" end of string, not "match character at" end of string -


i google , search site doesn't find similar question think it's rare question: write regexp

#<img .+?/font_image/(.{4})\.gif.*?># 

in preg_match() check pattern

<img src=".../font_image/xxxx.gif" ...> 

in text '>' missing due typo.

how can modify regexp match either > or end-of-string cases (note: can't use $ since wouldn't know last character @ end of string, tried #<img .+?/font_image/(.{4})\.gif.*?># doesn't work)?

just put >$ inside group delimited | . note don't use char class type of or operation since $ inside char class should loose it's special meaning.

<img .+?/font_image/(.{4})\.gif.*?(?:>|$) 

demo


Comments