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



.



Relevant Pages

  • Re: Complex regular expression
    ... Charles DeRykus wrote: ... you've eliminated the irrelevant leading/trailing *'s: ... Hm,, I'm not sure why that'd invalidate this approach. ... If $pattern were 123-45-6789 for instance, ...
    (comp.lang.perl.misc)
  • Re: regex question
    ... On 6/21/2013 12:45 PM, John Black wrote: ... I want to match on some pattern that is not ... but this seems to match pattern1 even if "string" comes later somewhere on the line. ... Charles DeRykus ...
    (comp.lang.perl.misc)