Racoon Racoon - 4 months ago 13
PHP Question

Find Regex word

What is regular expression to find tag like this:


Here is text and there is tag @username can be spaces here (#12345678) and this is end!


I need to find by:


  • Tag starts with "@"

  • Then somewhere will be "(#"

  • And always after 8 symbols from # will be ")"



So, important match parts are: @ (#********)

Thanks

Language is PHP

Valid:


@Martin's Van Der Buren (#6575GT67)


Not valid:


@Martin's Van Der Buren #6575GT67)

@Martin's Van Der Buren (6575GT67)

@Martin's Van Der Buren (#6575GT67

Answer

You can use:

@.*?\(#\d{8}\)

This will match an @ followed by any number of characters then the pattern (#12345678)

Comments