Complex regular expression

C

Charles DeRykus

Charles said:
Charles DeRykus said:
(e-mail address removed) 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.

Based on the OP's example, I was assuming that any match still needed to
capture exactly some subset of the pattern. I guess it was ambiguous
only to me...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top