|
Posted by Shoryuken on July 18, 2008, 1:53 pm
Please log in for more thread options >
> > Hello gents, here's the thing been confusing me for a while:
>
> > $regex="(\w+)\s([0-9]+)";
>
> > $a="Tom 1990"; # it's a match
> > $b="Jack xyz"; # not a match, because of $2 doesn't match ... but
> > here's my question, exactly how to inform the users of this unmatched
> > subgroup? (i.e. $2 is the problem, $1 is fine, etc.)
>
> > For a regex matching, is there a way to find which subgroups don't
> > match?
>
> You can use /gc and \G to match one piece at a time, without losing your
> place; something like
>
> my @matches = qw/ \w+ \s [0-9]+ /;
> my $string = 'Jack xyz';
>
> for my $match (@matches) {
> $string =~ /\G$match/gc
> or print "$match failed at position " . pos $string;
> }
>
> Ben
>
> --
> Outside of a dog, a book is a man's best friend.
> Inside of a dog, it's too dark to read.
> b...@morrow.me.uk Groucho Marx
This is a great idea, thanks!
And thanks the other guys for the good input, too!
|