CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
Perl Regex: not processing back references correctly


New User

Oct 9, 2012, 11:05 PM

Post #1 of 2 (9640 views)
Perl Regex: not processing back references correctly Can't Post


According to:


should not match


But I have checked out many perl online testing site and perl script also, all matches above string correctly.

I am confused now , which one is correct 1. Boost documentation 2. Perl script.
Please let me know which one is correct.

I am not able to understand ^(a*).*\1$ regex also. Please assist me to understand this also.

Thanks in advance.

Veteran / Moderator

Oct 10, 2012, 4:49 AM

Post #2 of 2 (9635 views)
Re: [rajkumar] Perl Regex: not processing back references correctly [In reply to] Can't Post


I see no reason why ^(a*).*\1$ should fail to match aaabba.

And I confirm that it DOES indeed match it.

The regex engine first tries "aaa", but fails on the back reference. It then backtracks and tries "aa", and fails again. It backtracks again and tries "a", and then succeeds.

Example on the command line:

perl -e '$c = "aaabba"; print "matched \"$1\"\n" if  $c =~ /^(a*).*\1$/;' 
matched "a"


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives