shemp has asked for the wisdom of the Perl Monks concerning the following question:
(yes i am looking for the case of 'C%O' which i also see sometimes)$name =~ s/(^|\s) C (\/|\\|%) O (\s|$) / % /xgi;
And then i want to replace forward of backslashes with &, as long as they do not have digits on both sides (which would be a fraction, which does sometimes appear in names i process). That is done through this regex:
The problem is that sometimes i want to perform only the second transformation without having done the first one, but i could not come up with any decent way to accomplish the second part with the exception of cases that are care-of's, as defined by the first part.$field =~ s/(?<!\d) # not preceeded by digits (?:\\|\/) # back or forward slash (?!\d) # not succeeded by digits / & /xg; # replace with '&' (globally)
Any thoughts?
Also, i think that using the separate regexes will work fine, i have worked around the problem of only wanting to perform the final stage without messing the earlier stages. Thanks for all the suggestions!$field =~ s/(?:^|[^A-Z]) ([A-Z])\/ ([A-Z])\/ ([A-Z]) (?:[^A-Z]|$) / $1$2$3 /xig;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex Question
by Aristotle (Chancellor) on Nov 15, 2005 at 20:08 UTC | |
|
Re: Regex Question
by Aristotle (Chancellor) on Nov 15, 2005 at 19:39 UTC | |
by Roy Johnson (Monsignor) on Nov 15, 2005 at 19:47 UTC | |
by Aristotle (Chancellor) on Nov 15, 2005 at 19:58 UTC | |
by Roy Johnson (Monsignor) on Nov 15, 2005 at 20:23 UTC | |
by shemp (Deacon) on Nov 15, 2005 at 20:07 UTC | |
by ikegami (Patriarch) on Nov 15, 2005 at 19:43 UTC | |
|
Re: Regex Question
by ikegami (Patriarch) on Nov 15, 2005 at 19:52 UTC | |
by Aristotle (Chancellor) on Nov 15, 2005 at 20:02 UTC | |
by ikegami (Patriarch) on Nov 15, 2005 at 20:11 UTC | |
by Roy Johnson (Monsignor) on Nov 15, 2005 at 20:16 UTC |