Search code examples
phpregexfunctionstr-replacepreg-replace-callback

Regular expressions replace


I need to remove

[0037][user name] 

combination from a sentence. In the first brackets always containing numbers eg:

[0032]

Digit count will not exceed than 4 by any chance. In the second brackets always containing letters eg:

[first name]

anyone have an idea how to do this?


Solution

  • You can use preg_replace() to implement regular expression syntax and try the following expression.

    $str = preg_replace('/\[\d+]\[[a-z ]+]/i', '', $str);