pirkil has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks, I am wondering how to define an exception from a character class in a regexp. Here is an example:
1. simple removal of punctuation:
2. I want to remove punctuation except the apostrophe. I don't want to make just:my $text = q{"This is dad's car." "OK", he said.}; $text =~ s{\p{Punct}}{}xmsg;
$text =~ s{(?<!dad)\p{Punct}}{}xmsg;
because I need to apply the regexp in a general way. This is maybe a trivial problem and I have overlooked something, but how can I do it? (With a conditional expression (?(condition)yes-pattern|no-pattern)?)
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Exception from a character class
by Anonymous Monk on May 30, 2013 at 10:46 UTC | |
|
Re: Exception from a character class
by AnomalousMonk (Archbishop) on May 30, 2013 at 19:06 UTC | |
|
Re: Exception from a character class
by ambrus (Abbot) on May 30, 2013 at 20:06 UTC | |
|
Re: Exception from a character class (user defined character properties \p{IsUserDefined} sub IsUserDefined )
by Anonymous Monk on May 30, 2013 at 20:53 UTC |