1

I have to check if a string matches bio control numbers for products. This link has the specifications (unfortunatly in german).

The numbers start with a country-code, followed by 3 characters and two or three digits. Here some examples:

DE-ÖKO-233
IT-BIO-053
DK-ØKO-79

This is the regex, I came up with: /[A-Z]{2}-[A-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŒŠŸ]{3}-\d{2,3}/

While it works perfectly fine on regex101.com, it doesn't work in my php-script as it returns an empty array.

$value = "DE-ÖKO-007";

preg_match('/[A-Z]{2}-[A-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŒŠŸ]{3}-\d{2,3}/', $value, $matches);

print_r($matches);

My expected output would be

Array(
    [0] => "DE-ÖKO-007"
)

but I actually get

Array(
)

Am I missing something in the way preg_match works?

Argee
  • 1,216
  • 1
  • 12
  • 22
  • As usual with Unicode letters, use `u` modifier, `preg_match('/[A-Z]{2}-[A-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŒŠŸ]{3}-\d{2,3}/u', $value, $matches);`, see [the PHP demo](https://3v4l.org/p3Q7s). – Wiktor Stribiżew Aug 06 '20 at 12:55
  • 1
    oha! thank you! works perfectly fine :) – Argee Aug 06 '20 at 12:56

0 Answers0