felix
felix

Reputation: 3

Match Some Text with Regex

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 :

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

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

Thank you...

Upvotes: 0

Views: 48

Answers (2)

charmian
charmian

Reputation: 491

You do not need | inside [], try this

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

[@#!] for the prefix

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

Upvotes: 0

Obsidian
Obsidian

Reputation: 947

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

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

And later you can replace &amp; with &

Upvotes: 1

Related Questions