Skip to content
Advertisement

Simple regex on string

I’m working on a simple mention system and in my PHP script and I need to extract client:6 from the larger text where one or more @mention like @[John Doe (#6)](client:6) will be present.

Ex. This is my text how do you like it @John and do you have any thoughts @Jane

In php the string will look like.

JavaScript

and i need to get an array with array('client:6','client:7')

Advertisement

Answer

One of many possible ways would be

JavaScript

See a demo on regex101.com.


In terms of regular expressions, this boils down to

JavaScript

In PHP this could be

JavaScript

And would yield

JavaScript

See a demo on ideone.com.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement