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

 



FiMko
New User

Sep 25, 2009, 12:11 PM

Post #1 of 3 (2662 views)
Problem with regex Can't Post

Hi all!

I have a problem with regex given below. Here is the target text:

Quote
Something text
TT-AAA-MMMM-1929 Something text
123 Something text
Something text 456 Something text


I just want to catch "TT-AAA-MMMM-1929" making a start from "123" or "456".
So, this regex works in my regex constructor (I don't know what type of engine it is based on) but the perl script finds nothing...

Code
@regexps = ["123", "456"]; 
for ($i = 0; $i < 2; $i++) {
$txt =~ m/TT-AAA-MMMM-\d{4}(?=(.+\r\n)*.+regexps[$i])/g;
print($&);
}


Could anybody help me with this regex?
Thanks in advance.


FiMko
New User

Sep 25, 2009, 12:54 PM

Post #2 of 3 (2658 views)
Re: [FiMko] Problem with regex [In reply to] Can't Post

Seems a problem with line breaks \r?\n works...


shawnhcorey
Enthusiast


Sep 26, 2009, 6:10 AM

Post #3 of 3 (2618 views)
Re: [FiMko] Problem with regex [In reply to] Can't Post

Try this:

Code
#!/usr/bin/perl 

use strict;
use warnings;

my $txt = <<EOD;
Something text
TT-AAA-MMMM-1929 Something text
123 Something text
Something text 456 Something text
EOD

my @regexps = ("123", "456");
for my $regexp ( @regexps ){
$txt =~ m/TT-AAA-MMMM-\d{4}(?=(.+\r?\n)*.+$regexp)/s;
print "$regexp: $&\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".

 
 


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

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