Greetings, Merry Monks of the Monastery -
I'm stumped on trying to figure out a regex for this, and it's a bit of surprise to me; I've been merrily regexing for years, but I've come a sudden cropper here. I'd appreciate some help.
I need to replace all tabs in a line that are not a) next to a double-quote, b) at the beginning of the line, or c) at the end of the line. Now, I
could say something nasty like
s/(?:^\t|\t$)/-=-|1|-=-/g;
s/([^"])(?:\t")/$1-=-|2|-=-/g;
s/(?:"\t)([^"])/-=-|3|-=-$1/g;
s/"\t"/-=-|4|-=-/g;
s/\t//g;
#...and then the obvious Opposite Thing
but... my Perlish soul yearns for something more - you know,
prettier. Isn't there some magic look-around regex that could do it all in one pass? I've been fiddling and fiddling with it, well past the point of practicality, and now I just want to know if it's doable.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.