Home > Blockchain >  Match Some Text with Regex
Match Some Text with Regex

Time:08-20

with this text ->

<p>sadadsadsad @Jack&nbsp;</p>
<p>@John Rich &amp; Sarah&nbsp;</p><p>sadadsadsadsadsadasd @Junior Cam AND Ken&nbsp;</p>
<p>
<br></p><p>asdsadasdasdasd #12345-S Company&nbsp;asdsadasdasd @Tom Mer AND Grace&nbsp;</p><p>asdadsadasd @Milo Elisa&nbsp;</p>

May I know what is the correct regex to pick up the following text :

  • @Jack
  • @John Rich & Sarah
  • @Junior Cam AND Ken
  • #12345-S Company
  • @Milo Elisa
  • @Tom Mer AND Grace

I have this regex but seems its not getting it right.

/([@|#|!].  )/gm

Thank you...

CodePudding user response:

If all names are guaranteed to end with &nbsp;, then you may try:

/([@#]. ?)(?=&nbsp;)/gm

And later you can replace &amp; with &

CodePudding user response:

You do not need | inside [], try this

/[@#!]([\w \-]|&amp; ) /gm

[@#!] for the prefix

[\w \-]|&amp; for names, numbers, spaces, - or &amp;

  • Related