Re: Complex regular expression

anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:
Charles DeRykus <ced@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
jayanthigk2004@xxxxxxxxx wrote:
Is it possible to write a regular expression for this ?

Pattern: 999-99-999

Where 9 is any number from 0 to 9


maybe I'm missing something but seems like `index' should do it once you've eliminated the irrelevant leading/trailing *'s:

my $pat = '999-99-999';

my ( $no_star = $some_str ) =~ s/\A\*//; $no_star =~ s/\*\z//;
print "match: $some_str" if index( $pat, $no_star ) == 0;

Not when "9 is any number from 0 to 9".

Hm,, I'm not sure why that'd invalidate this approach. If $pattern were 123-45-6789 for instance, this still works AFAICT.

Charles DeRykus