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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Help me in parsing the string

 



ajay_csv
New User

Sep 29, 2008, 4:20 AM

Post #1 of 3 (3897 views)
Help me in parsing the string 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.


shawnhcorey
Enthusiast


Sep 29, 2008, 5:13 AM

Post #2 of 3 (3894 views)
Re: [ajay_csv] Help me in parsing the string [In reply to] Can't Post


In Reply To
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)


ajay_csv
New User

Sep 29, 2008, 5:57 AM

Post #3 of 3 (3892 views)
Re: [ajay_csv] Help me in parsing the string [In reply to] Can't Post

 
shawn,

Thanks a ton!!! It has helped me a lot.

Regards,
Ajay Vikas.

 
 


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

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