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:
regex

 



perllearner
Novice

Jul 8, 2009, 5:07 AM

Post #1 of 5 (2778 views)
regex Can't Post

Hi,

I have some string like "000 05 27832 Food Chn KR FM CORP W/O AK - RMA", i want to process the first 3 characters, each should be of 0-9 and write it in a file.

I have an idea of using like

$var1 = [0-9]{3,}

and now comparing this with the above string. Can anyone pls help me wat this [0-9]{3,} literally means??


shawnhcorey
Enthusiast


Jul 8, 2009, 6:42 AM

Post #2 of 5 (2777 views)
Re: [perllearner] regex [In reply to] Can't Post


In Reply To
Hi,

I have some string like "000 05 27832 Food Chn KR FM CORP W/O AK - RMA", i want to process the first 3 characters, each should be of 0-9 and write it in a file.

I have an idea of using like

$var1 = [0-9]{3,}

and now comparing this with the above string. Can anyone pls help me wat this [0-9]{3,} literally means??


It means a syntax error. Try:

$var1 =~ /[0-9]{3,}/;

This means match the first string of characters in $var1 in the range of '0' to '9' for 3 to infinite times.

__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".


perllearner
Novice

Jul 8, 2009, 6:48 AM

Post #3 of 5 (2776 views)
Re: [shawnhcorey] regex [In reply to] Can't Post

thank you, But

I have this string "000 05 27832 Food Chn KR FM CORP W/O AK - RMA"

where i have to process only the first 3 characters,

can i use
if ( $var1=~ /^[0-9]{1,3} )
{
print "$var1";
}
*******

Where it prints only the string which has 0-9 in first 3 char, else it will not print it. Can you pls help me?


shawnhcorey
Enthusiast


Jul 8, 2009, 7:10 AM

Post #4 of 5 (2775 views)
Re: [perllearner] regex [In reply to] Can't Post


In Reply To
thank you, But

I have this string "000 05 27832 Food Chn KR FM CORP W/O AK - RMA"

where i have to process only the first 3 characters,

can i use
if ( $var1=~ /^[0-9]{1,3} )
{
print "$var1";
}
*******

Where it prints only the string which has 0-9 in first 3 char, else it will not print it. Can you pls help me?


I think you want:

Code
my @captured = (); 
if( @captured = $var1 =~ m{ \A \s* (\d{3}) }msx ){
print "@captured\n";
}


__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".


perllearner
Novice

Jul 8, 2009, 8:10 AM

Post #5 of 5 (2774 views)
Re: [shawnhcorey] regex [In reply to] Can't Post

 
Thank you very much....

 
 


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

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