Re: pattern matching
- Posted by Alyne & Warren <WCBaker at HOME.COM> Dec 29, 1999
- 450 views
Hi David! The code below is not written very concisely but I just tested it and it yields: string1 is Name: string2 is Name: string3 is Name: string4 is Name: Your match works -- you simply forgot the "=~" at the beginning of the match, which tells Perl that a match was made. Perl code below: $comparison="Name:"; #contains the string to scan for a match $comparison=~/.* ^Name: (.*)/; #I believe this is the kind of match you wanted print "string1 is $comparison" ; print "<br>"; $comparison="Name:"; #contains the string to scan for a match $comparison=~/^Name:/; print "string2 is $comparison" ; print "<br>"; $comparison="Name:"; #contains the string to scan for a match $comparison=~/Name:/; print "string3 is $comparison" ; print "<br>"; $comparison="Name:"; #contains the string to scan for a match $comparison=~/a/; print "string4 is $comparison" ; I fear I am dreadfully off-base, but I hope this might help in some way.... Cheers! --Warren >my pattern matcher *won't* work with something > like this: > > /.* ^Name: (.*)/ > > Because the wildcard on the left hand side will eat up "Name:". Are > wildcards like this allowed in Perl? > > -- David Cuny