
shawnhcorey
Enthusiast

Sep 29, 2008, 5:13 AM
Post #2 of 3
(10911 views)
|
Re: [ajay_csv] Help me in parsing the string
[In reply to]
|
Can't Post
|
|
Hi All, Please help me finding the match pattern for, my $t= "Error prone *12345* example"; my $pat="*12345*"; if ( $t =~ /$pat$) { print "good"; print "\n".$pat; } Aboe code is throwing Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE 12345*/ at chopfl.pl line 13. Please help me over this. Thank you, Ajay Vikas. The character * is a meta-character. It has special meaning inside a pattern. To match an actual *, there are two methods. First you can quotemeta your string (see `perldoc -f quotemeta`). Second, you can do it in the pattern itself with \Q my $pat = quotemeta( "*12345*" ); Or $t =~ /\Q$pat\E/ PS EDIT: Oops, there is a third method. This one is tricky. If your pattern in a literal string inside Perl, you can escape the * with a backspace but you'll need two of them. The first is interpreted by string interpolation to mean a backslash character. $pat = "\\*12345\\*"; If the pattern is in a text file you read in, you place only one backslash in it. __END__ I love Perl; it's the only language where you can bless your thingy. Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib. Get Markup Help. Please note the markup tag of "code".
(This post was edited by shawnhcorey on Sep 29, 2008, 6:17 AM)
|