
jaimitoc30
Novice
Apr 10, 2012, 1:09 PM
Post #3 of 6
(1417 views)
|
|
Re: [BillKSmith] Perl regex help.
[In reply to]
|
Can't Post
|
|
I must not understand your problem. I have prepared a complete perl program to demonstrate my understanding of it. use strict; use warnings; my @samples = ( 'acti', 'baja', 'info', '5.00 65436765', '10.00 65436765', ); my $regex1 = qr/^\s*([0-9]{1,2}[]{0,1}|[0-5]{1,2}[][0,5]{0,1}[0]{0,1})\s+([0-9]{8})\s*$/; my $regex2 = qr/^\s*([0-9]{1,2}[]{0,1}|[0-5]{1,2}[][0,5]{0,1}[0]{0,1})\s+([0-9]{8})| (acti|baja|info)\s*$ /x; foreach my $text (@samples) { if ($text =~ $regex1) { print "Regex_1 Matched: $text\n"; } if ($text =~ $regex2) { print "Regex_2 Matched: $text\n"; } } You expect $regex1 to match the numeric examples and $regex2 to match all the examples. You claim that $regex1 matches something, but $regex2 does not. This is not at all the case. $regex2 matches the text examples. $regex1 does not match anything. Please post a complete program that demonstrates your problem. Explain what is wrong with its output. Ok, I have tested it: localhost# perl regexval2.pl Regex_2 Matched: acti Regex_2 Matched: baja Regex_2 Matched: info Regex_1 Matched: 5.00 65436765 Regex_2 Matched: 5.00 65436765 Regex_1 Matched: 10.00 65436765 Regex_2 Matched: 10.00 65436765 Now, look at this code:
#!/usr/local/bin/perl $text="acti"; $text =~ qr/^\s*([0-9]{1,2}[]{0,1}|[0-5]{1,2}[][0,5]{0,1}[0]{0,1})\s+([0-9]{8})| (acti|baja|info)\s*$ /x; $text= $1; print "RESULT: $text\n"; print "END"; The result is this: localhost# perl regexval.pl RESULT: END it won't match, I did a copy paste.. whats the difference then??
|