DEFINE regex

can someone explain why this regex

/(?(DEFINE)
  (?<alnum>                      [a-zäöüßÖÜÄ0-9-]+ )    
  (?<warranty_word>              (?&alnum)?garantie[*]?)
)
(?&warranty_word)/six

only Warranties in Vor-Ort-Garantie comply , but this other https://regex101.com/r/oJKV1Q/1

/(?(DEFINE)
  (?<warranty_word>              ([a-zäöüßÖÜÄ0-9-]+)?garantie[*]?)
)
(?&warranty_word)/six

fully compliant with Vor-Ort-Garantie https://regex101.com/r/axvJmA/1

as well as how I can fully combine it while maintaining separate definitions of each part

+4
source share
2 answers

, , , . "" . "Vor-Ort-", (?&alnum) "Garantie", (?<warranty_word> ...) , (?&alnum) .


: , ascii, u, , , utf8

# ö is encoded with C3 B6

var_dump(preg_match('~[ö]~', "\xC3")); 
# int(1)

var_dump(preg_match('~[ö]~u', "\xC3"));
# bool(false)

Ä, Ö Ü , .

+2

. , , PCRE ( ):

, , . , , ,

, , , (?&alnum) - , . 3 Jahre Vor-Ort-Garantie 3. , (?&alnum) ( ), .

, . , Perl:

my $alnum = "[a-zäöüßÖÜÄ0-9-]+";
my $warranty_word = "(?:$alnum)?garantie[*]?";

if ($string =~ /$warranty_word/)
{
    ...
}

, , , . , .

+2

Source: https://habr.com/ru/post/1658808/


All Articles