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: Re: [ajay_csv] Help me in parsing the string: Edit Log


Sep 29, 2008, 5:13 AM

Views: 12042
Re: [ajay_csv] Help me in parsing the string

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 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*" );


$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.


I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at 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)

Edit Log:
Post edited by shawnhcorey (Enthusiast) on Sep 29, 2008, 5:30 AM
Post edited by shawnhcorey (Enthusiast) on Sep 29, 2008, 6:17 AM

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

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