CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
regex helppppppppp!!!!!!

 



akhilak
Novice

May 15, 2007, 7:36 PM

Post #1 of 2 (3188 views)
regex helppppppppp!!!!!! Can't Post

Hi there,
Could anyone please help me with a regular expression. I want to find a word which ends with a + symbol in a string (Ex. abc+, perl+). I tried using /[\w]+\+$/. But this regex is returning all the words which starts with a word character irrespective of whether it has a + at its end. Could someone please give me a solution for this. It would be a great help.

Thanks in Advance


numberwhun
Novice


May 22, 2007, 9:58 AM

Post #2 of 2 (3171 views)
Re: [akhilak] regex helppppppppp!!!!!! [In reply to] Can't Post

Well, here is one way of doing it:


Code
use strict; 
use warnings;

my $words = "abc+, perl+, word, this, that+";

my @wordsArray = split(/\,\s*/, $words);

foreach(@wordsArray)
{
print("$_ \n") if($_ =~ m/\w+\+$/);
}


Depending on how the words in the string are arranged (ie: with or without the commas and such), this could be easily modified to fit your needs.

Regards,

jlk
"Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall"

"Lack of planning on your part does not constitute an emergency for me!"

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives