perl - Why does adding a character class to the end of a regex fail to match hex numbers? -
perl accepts:
my @resultado = $texto =~ /[^g-zg-z]$re{num}{real}{-base=>16}/g
but doesn't accept:
my @resultado = $texto =~ /[^g-zg-z]$re{num}{real}{-base=>16}[^g-zg-z]/g
i add [^g-zg-z]
@ end; @ beginning works not @ end. why? want print hexadecimal numbers but, example, in cases there word 'call' should not 'ca' hexadecimal number.
the character class [^g-zg-z]
matches single character not in range g through z. not want matching hexadecimal digit. example, if hex number occurs @ end of string (that is, nothing follows it), match fail.
you did not provide sample data. pattern such as
my @resultado = $texto =~ /\b([0-9a-fa-f]+)\b/g;
may give want. \b
matches @ word boundary, , constrains hex digits occur within single “word.”
in regexp::common terms, above line expressed as
my @resultado = $texto =~ /\b($re{num}{int}{-base => 16})\b/g;
Comments
Post a Comment