11
votes

Testing the PHP regex engine, I see that it considers only [0-9A-Za-z_] to be word characters. Letters of non-ASCII languages, such as Hebrew, are not matched as word characters with [\w]. Are there any PHP or Perl regex escape sequences which will match a letter in any language? I could add ranges for each alphabet that I expect to be used, but users will always surprise us with unexpected languages!

Note that this is not for security filtering but rather for tokenizing a text.

2

2 Answers

1
votes

Try \p{L}. It matches any kind of letter from any language. If you don't want to use char set [].