Hello monks, I'm trying to write a regex to switch some ports in a design. I have an array of values, one of them is say:
\u0/r0/rcnt[3]
I then have a cell like so:
NOR2X0 U2905 ( .IN1(\u0/r0/rcnt[3] ), .IN2(\u0/r0/n43 ), .QN(n1699) ) +;
I need to switch the values in after the brackets in .IN1 and .IN2 so the output should be:
NOR2X0 U2905 ( .IN1(\u0/r0/n43 ), .IN2(\u0/r0/rcnt[3] ), .QN(n1699) +);
The part of the code doing that right now is:
foreach my $val (@nets_q) { $data =~ s/( [NOR|OR].*.IN1\()($val)(\).*IN2\()([^\)]*)(.*)/$1$4$3 +$2$5/g; }
But this throws an error:
Unrecognized escape \u passed through in regex;
So it is considering the "\u" part of "\u0/ro/rcnt3" as an escape character. How would I go about doing this? Is this the right way? Thanks in advance!

In reply to Passing a variable to a regex by mavericknik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.