in reply to Re: Regex Subexpressions
in thread Regex Subexpressions

Yeah, sorry for changing the post around. I thought I was replying to myself when in fact I was editing the original post.

Anyhow, here's a more concrete example:
@keywordList = ('john', 'john.smith', 'john.smith@mail.com'); $combinedExpression = combine(@keywordList); # The combined expression looks something like this: # (john(?:\.smith(?:\@mail\.com)?)?) $searchText = "john's username is john.smith and his email address is +john.smith@mail.com"; while $searchText =~ /$combinedExpression/g { print "$1\n"; }
For this example, I expect to get these results:

john
john
john.smith
john
john.smith
john.smith@mail.com

Essentially, for every occurrence of every one of my keywords, I need to get a result, even if those keywords occur within other keywords in the input text.

Replies are listed 'Best First'.
Re^3: Regex Subexpressions
by grinder (Bishop) on Sep 10, 2005 at 08:35 UTC

    For one possible implementation of your combine subroutine, consider:

    use Regexp::Assemble; sub combine { my $str = Regexp::Assemble->new->add(@_)->as_string; qr/($str)/; }

    - another intruder with the mooring in the heart of the Perl