WebmastTroy
02-05-2002, 04:18 PM
Hello all.
I am needing some help with a line of coding.
For an abbreviated example:
$name = "First Middle Last";
I am wanting a line of coding to pull out "Middle" in that variable.
I tried:
$name =~ s/First .*? Last//gi;
But all that does is totally cut out "Middle" and shows me the rest. Is there a variable that is sent back with the contents of the .*? ?
Any help is appreciated.
You can contact me via AIM using "WebmastTroy".
Thanks!
Troy
DjPaj
02-05-2002, 05:38 PM
Hehehe, messed this one up, read the one below.
DjPaj
02-05-2002, 05:41 PM
Hmmm...I'm not too hot with Perl, use PHP damn it!!! J/K
try this:
$name="First Middle Last";
while($name =~ /\w+(?=\s)/g)
{
print "$&\n";
}
This should give you:
First
Middle
Last
Now you could swap out the print and set variables.
Like I said I am no good with Perl, I was flipping through the good ole' Perl Black Book and saw this and thought it may be of some assistance to you.
Prolly not though, there are prolly some Perl experts here. Who will tell me this crap and doesn't work, but hey at least I tried
:D
Happy 100 Post To MEEEEE!!!!!! :dunce:
WebmastTroy
02-06-2002, 10:30 AM
Thanks for your help, but I guess I'll stop beating around the bush.
I'm trying to get the text between 2 different HTML tags on a web page. I've seen it done (I've even done it, but forgot and lost the script :( ) so I know it's possible.
Your script would work, except that it splits the text at the spaces and moves them apart. Thats my fault...my example wasn't good.
Thanks.
Troy
getweb
02-06-2002, 10:44 AM
Try something like this:
$input = "<h1>PERL is KING</h1>";
$input =~ m|<h1>(.*)</h1>|i;
$phrase = $1;
print $phrase . "\n";
It uses "expression memory" or "pattern memory" I don't remember the term. It means that the part of the match expression that is in parenthesis gets put into a variable $1. This is true for multiple parenthesis sets, with the next set being $2... $3... etc.
WebmastTroy
02-06-2002, 02:20 PM
That did it!
Thanks!
-Troy