Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

matchin a string inside of another string

by Anonymous Monk
on Apr 05, 2004 at 04:10 UTC ( [id://342566]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://342566]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-24 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found