tags:

views:

84

answers:

3

Hello there!

Could you please point me to the mistake in my regular expression?

/[\x{4e00}-\x{9fa5}]*[.\s]*\[\/m\][\x{4e00}-\x{9fa5}]/u

My string starts with chinese character ([\x{4e00}-\x{9fa5}]), which is followed by any character and ends with '[/m]' and another chinese character. So the string possibly could look like:

我... some text goes here (contains any characters including spaces and new lines)... [/m]我

But unfortunately my regular expression doesn't work as expected.

Thank you.

+1  A: 

It looks like you probably want to replace the first '*' with '+' to ensure you have at least one matching character in the initial spot and you can drop the character group with '\s' and just use '.' as that will match any character. Also, if this is to be a complete line I would start the regex with '^' and end it with '$'.

Aneurysm9
still not working...
Josh
+1  A: 
  1. If there should only be one Chinese character at the beginning, drop the first '*'.
  2. However you should keep the '[.\s]', because '.' doesn't match newlines (I think).
  3. Once that's done, make sure the problem comes from the regexp and not from the php code.
jdb
A: 
/[\x{4e00}-\x{9fa5}][.\s]*\[\/m\][\x{4e00}-\x{9fa5}]/um
Mez