I'm not sure if this is going to be of any use but you might be able to detect that the digits are at the end of the string rather than the 'b'. You could do this by making the match for 'b' conditional on whether you've got to the end so that the match doesn't actually fail if the 'b' isn't there. The code may do a better job of explaining what I mean.
#!/usr/bin/perl -l
#
use strict;
use warnings;
my @strings = qw{
a123ga123b
a123bdfda123
a123effa123
a123
d663h
};
my $len;
my $rsLen = \$len;
my $rxCondMatch = qr
{(?x)
a
(\d+)
(?{ print q{digits at end of string} if pos() == $$rsLen })
(??{ if ( pos() != $$rsLen ) { q{b} } })
};
foreach my $string ( @strings )
{
$len = length $string;
print $string;
print q{Match} if $string =~ $rxCondMatch;
print q{-} x 20;
}
Here's the output.
a123ga123b
Match
--------------------
a123bdfda123
Match
--------------------
a123effa123
digits at end of string
Match
--------------------
a123
digits at end of string
Match
--------------------
d663h
--------------------
I hope this can be of use to you.
Cheers,
JohnGG
Update: Corrected error in code, testing against $len instead of $$rsLen in (?{ ... }) block
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.