By the way, you're a java programmer, right? I'm not being perjorative or anything (well, maybe a little :-), but I had never heard of a "reluctant qualifier", and when I googled for it, I got mostly Java matches. That plus the lowerCaseMixedWithUpperCase variable names kinda gave you away ... ;->#!/usr/bin/perl -w use strict; use warnings; # Prototypes sub findMatches($$); # Input data my @keywordList = ( 'john', 'john.smith', 'john.smith@mail.com' ); # Main program my $searchText = "john's username is john.smith and his email address +is john.smith\@mail.com"; my $pmatches = findMatches($searchText, \@keywordList); map { print "$_\n"; } @$pmatches; # Subroutines # # Inputs: $1 ... the text string to match against # $2 ... a pointer to the list of valid matching substrings # # Outputs: $1 ... a pointer to a list of all matches # sub findMatches($$) { my ($text, $plist) = @_; my @matches; foreach my $pattern (@$plist) { while ($text =~ /($pattern)/g) { my $result = $1; # Got a match in $1 push @matches, $result; # Save it to our master res +ults list # Now trim off the first character (otherwise we'll be mat +ching # against the same substring (think 'deep recursion'), and + call # this subroutine again for recursively generated sub-matc +hes. # Whatever we get (if anything) is added to the list. # $result =~ s/^.//; my $psubstr = findMatches($result, $plist); push @matches, @$psubstr; } } return \@matches; }
In reply to Re: Regex Subexpressions
by liverpole
in thread Regex Subexpressions
by BenjiSmith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |