I'm curious. Question of style, why the square braces as delimiters? There are no slashes in what is matched, so there's no problem regarding leaning toothpicks.
I had to think for an extra second or two to figure out what you were doing, which in fact is quite clever. Bear with me, I want to see what this looks like:
s/(?<=[a-m])(?=[n-z])/5/g;
I dunno, somehow that seems clearer to me. I think it is because otherwise I find my eyes skipping back and forward too much between the character classes and the s-op delimiters. (But ++ all the same, I'll keep this technique in mind).
- another intruder with the mooring of the heat of the Perl
| [reply] [d/l] |
Basically, I got fed up with writing some regexes and substitutions with /s and then having to choose a different delimiter to avoid leaning toothpicks, then a different delimiter somewhere else to avoid conflicts with the fiorst choice and so on.
Then I discovered that using balanced delimiters meant that I rarely had to switch delimiters. Of the choices, () are just too common in regex, {} look like code blocks and are also used in regex.
I tried <> for a while, and they are a pretty good choice, but of the four, despite that they are themselves fairly common in regex, I found that I preferred []. So I now use them for all my regexes. I think I only encountered one time when I had problems with using them and that waas in a monster regex attempting to parse XML.
Historically, I am a strong believer in consistancy, and being able to use the same delimiter for all my regex (and other quote-like constructs) just makes my code more self-consistant.
Personally, I can't wait for characters to become consistantly 32-bits. Not only would that do away with the variable byte-length encoding problem that comes from utf and the performance hit that entails, but it gives more than enough space in the character set to introduce a dozen or so more sets of balanced pairs that would allieviate much of this type of problem completely.
I noticed that Bob Bemer, the father of ASCIIdied recently. Maybe it's time to let ASCII go to and invent a completely new set of symbols for computing:)
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
| [reply] [d/l] [select] |