Sunday, 15 September 2013

Concatenate two PCRE regex, one with unicode characters

Concatenate two PCRE regex, one with unicode characters

I want to write a regex for phone numbers. The first pattern uses english
numbers and the second uses persian numbers. How do concatenate these
patterns using |?
$pattern1 = '/^(\d{4})?\s?[1-9]{1}[0-9]{6}$/';
$pattern2 =
'/^([\x{0660}-\x{0669}]{4})?\s?[\x{0661}-\x{0669}]{1}[\x{0660}-\x{0669}]{6}$/u';
This doesn't work:
if (preg_match("($pattern1)|($pattern2)", $phone_number))...
And prints this warning:
Warning: preg_match(): Unknown modifier '|'
I'm also not sure whether the /u delimiter should be placed at the end of
second pattern and each subpattern(pattern1 and pattern2) should have
their delimiters OR whole concatenated pattarn should have only one
delimiter(e.g/pattern1|pattern2/u)

No comments:

Post a Comment