0

I constructed the following regex

preg_match_all('#(autom(.*?)tic|(.*?)anual)#', $str2b, $gears);

but I want to change it to match greek characters. I would like to match the words βενζίνη and πετρέλαιο but I don't get it to work.

preg_match_all('#(βενζί(.*?)η|πετρέλ(.*?)ιο)#', $str2b, $gears);

How can I do this?

anubhava
  • 761,203
  • 64
  • 569
  • 643
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
  • I would avoid embedding unicode in regular expressions unless the engine doesn't support \u or \x{}, and does unicode. Just my opinion. –  Oct 04 '13 at 19:30

1 Answers1

5

You should use /u regex switch for unicode matching:

preg_match_all('#(βενζί(.?)η|πετρέλ(.?)ιο)#u', $str2b, $gears);

btw you can use \p{Greek} property for matching Greek letters.

anubhava
  • 761,203
  • 64
  • 569
  • 643