in reply to Re: Problem with a text-parsing regex
in thread Problem with a text-parsing regex
... "any punctuation except hyphen" ...
This can be expressed without experimental features by a "double-negative" character class trick:
class of all characters that are [^-[:^punct:]] ^ ^ | | | +--- and also not a not-punct (i.e., or is a [:punct:]) | +--- not a hyphen
See perlrecharclass.Win8 Strawberry 5.8.9.5 (32) Sat 05/07/2022 18:36:51 C:\@Work\Perl\monks >perl use strict; use warnings; for my $char (split '', '#%-&*') { printf "'%s' %smatch \n", $char, $char =~ m{ \A [^-[:^punct:]] \z }xms ? '' : 'NO ' ; } ^Z '#' match '%' match '-' NO match '&' match '*' match
Update: The double-negative trick also works with "traditional" \s \d \w etc. character classes that have complements. E.g., the pattern "any word (\w) character except an underscore" can be defined as [^_\W].
Give a man a fish: <%-{-{-{-<
|
|---|