kr123 has asked for the wisdom of the Perl Monks concerning the following question:

I'm attempted to substitute and replace some text, but the text in my substitution is interfereing with my \1 variable. Does anyone know of some sort of a NULL character I can place between my \1 variable and the surrounding text?

For example, I am using the statement:

s/(some) text/\155/

I want the new string to read:

some55

But what I assume is happening is Perl tries to find match 155 rather then match 1.

Replies are listed 'Best First'.
•Re: In substituation regex, how to differentiate \1 from surrounding text
by merlyn (Sage) on May 19, 2004 at 20:53 UTC
      And on the pattern side, you can put it in non-capturing parentheses.

      The PerlMonk tr/// Advocate
Re: In substitution regex, how to differentiate \1 from surrounding text
by Enlil (Parson) on May 19, 2004 at 21:07 UTC
    According to perlre:

    There is no limit to the number of captured substrings that you may use. However Perl also uses \10, \11, etc. as aliases for \010, \011, etc. (Recall that 0 means octal, so \011 is the character at number 9 in your coded character set; which would be the 10th character, a horizontal tab under ASCII.) Perl resolves this ambiguity by interpreting \10 as a backreference only if at least 10 left parentheses have opened before it. Likewise \11 is a backreference only if at least 11 left parentheses have opened before it. And so on. \1 through \9 are always interpreted as backreferences

    So unless you have 155(or 15) open parens before you shouldn't have a problem .. but you should read Warning on \1 vs $1 (also in perlre as well)...

    -enlil