in reply to pcre regex

Show us some sample data that fails and some test code. If the problem is real you shouldn't need more than a few lines of data and a few lines of code to reproduce the problem.

Are you sure the pattern you want to match is at the start of the line? Could it be that you are reading the entire file into a string and are then trying to match against that string? If so you probably need to use the m (multiple line match) switch. Consider:

use strict; use warnings; my $str = <<TEXT; First line 1234X last line TEXT print "Matched\n" if $str =~ /^\d{4,4}[A-Z0-9]$/; print "Multi-matched\n" if $str =~ /^\d{4,4}[A-Z0-9]$/m;

prints:

Multi-matched
True laziness is hard work

Replies are listed 'Best First'.
Re^2: pcre regex
by Anonymous Monk on Apr 06, 2012 at 10:41 UTC

    Yes have to search in multilines so i used /m but it still does not give any matches. I think the problem is with ^ and $ as only regex having these identifiers are giving me problem rest ase working fine such as for email validation

    /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g