in reply to Re: How we can separate a backref from a digit?
in thread How we can separate a backref from a digit?

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: How we can separate a backref from a digit?

Replies are listed 'Best First'.
Re^3: How we can separate a backref from a digit?
by BrowserUk (Patriarch) on Mar 18, 2011 at 09:03 UTC
    Thanks, but \1+ is not correct.

    Sorry that one of the 5 methods didn't meet with your approval.

    By way of compensation, here's five more that might not:

    print "Match1\n" if "aa1" =~ /^(a)\1[1]$/;; Match1 print "Match1\n" if "aa1" =~ /^(a){2}1$/;; Match1 print "Match1\n" if "aa1" =~ /^(a)\1(?=)1$/;; Match1 print "Match1\n" if "aa1" =~ /^(a)\1(?<=)1$/;; Match1 print "Match1\n" if "aa1" =~ /^(a)\1(?{})1$/;; Match1

    I think I prefer the first of these.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      C'mon... now you're just showing off... :-D (Btw, this is a great thread... thanks for asking the questions, guys... I copied this one into my personal folder...) --Ray

      Update: here're my couple to add...

      print "Match1" if "aa1" =~ /^(a)\1(1)$/; #of course this places 1 in $ +2
      another silly one...
      print "match" if "aa1" =~ /^(a)\1(?:[^\s\S]*)1$/; #buwahahaha... kind +of the opposite of Perl Golf...

        FWIW: I now think that the "proper" way to do this is /(a)\1[1]$ because I seem to recall that circa 5.8.3 or 5.8.4, code was specifically added to the regex engine to cause character classes that contained a single character to be optimised away to that character. This was done because explicitly because it makes the use of the construct as an escaping mechanism so useful and clear.

        Ie. /[f][r][e][d]/ becomes exactly equivalent to /fred/, including its runtime performance.

        Maybe someone out there has a reference to the change, I looked but could not find it.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: How we can separate a backref from a digit?
by ikegami (Patriarch) on Mar 18, 2011 at 08:00 UTC

    Exactly one repetition