php - Hashtag preg_replace -
I have a web app that is creating and linking to #hashtags
and I have noticed that if a person makes #hashtag
of # JB22
that the following code breaks.
far regex I have a #hashtag
$ users = preg_replace ( "~ (& lt; Var data-type = \" user \ "class = \" user highlights \ "id = \" (. *?) \ "& Gt;) (. *?) (& Lt; / var & gt;) ~", "& lt; _link & Gt; $ 2 | $ 3 & lt; / _ link & gt; ", start $); $ Tag = preg_replace ( "~ (& lt; var data-type = \" tags \ "class = \" tagHighlight \ "id = \" (. *?) \ "& Gt;) # (. *?) ( & Lt; / var & gt;); "," & lt; _link> tags: // $ 3 | # $ 3 & lt; / _link & gt; ", $ users); $ Last = preg_replace ("~ (^ | \\ s) # (\\ w * [a-zA-Z _] + \\ w *) ~", "& lt; _link> tag: // $ 2 | $ 2 & lt; / _ Link & gt; ", $ tags);
change it to [a-zA-Z _] +
with [a-zA-Z_0- 9] +
or if you only want a number at the end of the pattern, then you ([a-zA-Z _] + [a-ZA] -Z_0-9] +?)
.
Comments
Post a Comment