Thanks, Yes I can see that the grouping affects the backreference. I had tried various combinations and it definitely helps to use the (?:) grouping construct.

If anyone's interested, I finally got it figured out to my own satisfaction. The problem stems from the placement of the + multiplier, if you place it as I did originally (reduced to it's simplest form):

/(\\)+\1/
Then the original (\\) matches at least one \. This is then muliplied any number of times and followed by a single \ (since that's what the () stored). The effect of this is to match any number more than one. What you actually need is:
/(\\+)\1/
This matches at least one, but possibly more \, this group of \s are then stored as the backreference and the whole expression will only match if there are an even number of \s. :-)

It all seems a lot simpler now that I've got it figured out, it just didn't seem that way when I was working through it.

Thanks for Reading

Nuance badly copying Simplicus


In reply to RE: RE: RE: Re: Backslashes in regular expressions by nuance
in thread Backslashes in regular expressions by nuance

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.