Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

lets say i have a string "bla foo bar letters stuff qwerty" and I need everything between bla and qwerty, but i also need to be able to match "bla foo qwerty" and "bla foo bar bla oontz letters meh stuff qwerty"
what is the simplest regex necessary to do this as i currently have /(\w*?\s*?\w*?\s*?\w*?\s*?\w*?\s*?\w*?\s*?\w*?\s*?)/ and that is ugly.

Replies are listed 'Best First'.
Re: matchin a string inside of another string
by davido (Cardinal) on Apr 05, 2004 at 04:18 UTC
    my @strings = ( "bla foo qwerty", "bla foo bar bla oontz letters meh stuff qwerty", "bla foo bar letters stuff qwerty" ); foreach my $string ( @strings ) { print "Match.\n" if $string =~ m/\bbla\b[\w\s]*?\bqwerty\b/; }

    Dave

Re: matchin a string inside of another string
by nmcfarl (Pilgrim) on Apr 05, 2004 at 04:32 UTC
    I may be missing the point here but would something like this work?
    $content= "bla foo bar letters stuff qwerty"; if ($content =~ /bla (.*?)qwerty/){ print "matched!\n"; @stuff = split /\s+/, $1; print "The stuff ".join(" ", @stuff)."\n" if @stuff; }
    Basically I'm getting all the stuff between the tokens, and splitting that on whitespace, to produce the @stuff array.