ISAI student has asked for the wisdom of the Perl Monks concerning the following question:
Why do I need the add an addition "\\" before the sqare braces (in the substring) when matching the substring? -ISAI student#!/bin/perl -w $p= "horraen=sumsel\[13\]\)\n"; $m="sumsel\[13\]"; print join("","this is \$m:",$m,"\n"); print $p; if ($p=~m/en=$m\)/) {print "yeah!\n";} else {print "why isn't it matching?\n";} $m=~s/\[/\\\[/g; $m=~s/\]/\\\]/g; print join("","this is \$m:",$m,"\n"); if ($p=~m/en=$m\)/) {print "yeah!\n";} else {print "what will I do now?\n";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regexp matching with "\[" in the substring to be matched
by rev_1318 (Chaplain) on Jul 05, 2005 at 11:54 UTC | |
|
Re: regexp matching with "\[" in the substring to be matched
by prasadbabu (Prior) on Jul 05, 2005 at 12:13 UTC | |
|
Re: regexp matching with "\[" in the substring to be matched
by nobull (Friar) on Jul 05, 2005 at 16:39 UTC | |
|
Re: regexp matching with "\[" in the substring to be matched
by tlm (Prior) on Jul 06, 2005 at 02:12 UTC |