This falls into the general class of "I'm using a regex, but my expression is starting to look like noise." The fastest solution in this case is use the x modifier
since you don't have any whitespace in your expression:
s/ \) ([^()]+) \(
/ ] $1 [
That's your original expression with extra whitespace.
I personally don't see the value in reducing your character count by 2 by avoiding the backslashes in the first place, but this type of process is always susceptible to Leaning_toothpick_syndrome. If I'm doing something like this, with potential nesting and the like, I always build a tree using tokens. My experience has generally shown that in these scenarios the fast solution is never actually fast.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In reply to Re: $1[
in thread $1[
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||