Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extracting pharse froma string

Status
Not open for further replies.

justme77

Technical User
Feb 4, 2001
19
0
0
SG
Hello,
anyone noe whether it's possible to extract a certain pharse or word from a string or sentence?

Thanks for answering.
cheers,
Just Me!!
 
sure...

$str = "This is a sentence.";

$str =~ /is/g;

$phrase = $&; adam@aauser.com
 
Thanks Luciddream,
this is still not quite what i want though. Maybe i'm not clear enough, here an exampl to show what i want:

suppose i got this string "this is an example ... help me.". I would like to extract whatever phrase is between "example" and "help". Please note that I do not know what's between these 2 words but I'll like to extract whatever's between them.

Any solutions? Thank you. cheers,
Just Me!!
 
[tt]$string =~ m~example(.*)help~;
$phrase = $1;[/tt]
"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Or you could increase it's power by making it search between two variables:

i.e.,

[tt]
$string = "this is an example ... help";
$one = "example";
$two = "help";

$string =~ m~$one(.*)$two~;
$phrase = $1;

print "$phrase";
[/tt]

So you could get the values of $one and $two from user input or something like that, and then do what you want to do with $phrase.

Hope this helps,

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top