Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl will not match my RegEx pattern....

by AnomalousMonk (Archbishop)
on Mar 18, 2014 at 17:45 UTC ( [id://1078837]=note: print w/replies, xml ) Need Help??


in reply to Perl will not match my RegEx pattern....

A quick check shows all strings match as you seem to expect. Can you be more specific about what you mean by "doesn't match on a single one"? As Bloodnok has asked, are you really, really sure about your data?

c:\@Work\Perl\monks>perl -wMstrict -le "my @seatlocs = (qw(A1.23BC U2.60L R2.32 C1.3L AB3.45E D45.1A), 'Some +Bldg'); ;; for my $loc (@seatlocs) { print qq{'$loc' }, $loc =~ m{ \b [A-Z]{1} \d{1} \. \d+ [A-Z]* }xms ? 'Correct' : 'Invalid'; } " 'A1.23BC' Correct 'U2.60L' Correct 'R2.32' Correct 'C1.3L' Correct 'AB3.45E' Invalid 'D45.1A' Invalid 'Some Bldg' Invalid

BTW:  [A-Z]{1} is the same as  [A-Z] is the same as  [[:upper:]] and  \d{1} the same as  \d

Replies are listed 'Best First'.
Re^2: Perl will not match my RegEx pattern....
by FierceMoose (Initiate) on Mar 19, 2014 at 14:52 UTC

    I suspect the data as well, but I'm not sure what can be done to clean it up with out altering the actual data. Chomp has had not change on operation either. Perhaps I need to convert it to a quoted word for RegEx to work?

    my $acopy = qw($SeatLoc);

    I'm somewhere between novice & intermediate in my experience and not immune to the 'obvious' mistake. ;-)

      qw does not interpolate variables. This statement is equivalent to
      my $acopy = '$SeatLoc';

      Note the single quotes.

      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Perhaps I need to convert it to a quoted word for RegEx to work?

      Blindly converting something that's already a string to a string is unlikely to help. You already know that the regex you provided works for the sample strings you provided. Find out what your data really looks like!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1078837]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found