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


May 15, 2007, 7:36 PM

Views: 8332
regex helppppppppp!!!!!!

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


May 22, 2007, 9:58 AM

Views: 8315
Re: [akhilak] regex helppppppppp!!!!!!

Well, here is one way of doing it:

use strict; 
use warnings;

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

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

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.


"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!"