I am using a PHP regular expression to change usernames to pretty links in text.
Firstly, It looks for an @ sign
,
Secondly, It checks if the @ sign
has a user id touching it, E.G. @User10
,
Thirdly, It makes sure that the user id is between 1 and 20 characters,
Fourthly it makes the links pretty.
This is my Regex
/(?<=^|\s|[([])\@([a-zA-Z0-9_]{1,20})/
This regex works fine for these text examples
@User1 This is a test string @User2
@User3
But it does not work in these text examples
<br>@User1 Hello John@User2
All of these Users should be matched but they are not being matched if a string is touching the @ sign
before it.
I have an online regex example set here. http://regex101.com/r/zK9kC4