Regex, or maybe regexp, but not regrex.. That doesn't make any sense : p I have no idea what you mean with "section in red." However, there's a few things wrong with your code:
What is $mark? Don't you mean $marker? As it stands, your snipped would die under strict, and in non-strict $mark would be undefined, which would be interpreted as an empty string; You'd be replacing all empty strings with empty strings, effectively achieving nothing at the cost of doing a lot. Also, that if is pretty worthless if all you using it for is to assign $1 you might as well write my ($marker) = message =~ /regex here/; But assuming you mean "delete all words that start with a #," then yeah, there's a much simpler way: > s/#\w*//g; Which uses the /g modifier, explained in perlretut[0] and perlop[1]. Meanwhile, if you mean "if a word start with #, delete it from everywhere in the script", you could do something like > s/$+{word}//g while s/ \# (?<word> \w+ ) //x; > This uses named captures, explained in perlretut and perlre[2]. You could do without them though. Brian. [0] http://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl [1] http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators [2] http://perldoc.perl.org/perlre.html On Wed, Mar 23, 2011 at 10:05 AM, Mike Blezien <mick...@frontiernet.net>wrote: > Hello, > > I'm working on a simple regrex issue which I got to work but I think > there's a better way to do this. This is what I have right now. I need to > simply remove the string section in red. > > my($marker); > my $message = "Why are we here? To bless, inspire and uplift one another. > #TRB #inspiration #loa"; > if($message =~ /\#(.*)/i) { $marker = $1; } > $message =~ s!$mark!!gi; > $message =~ s!\#!!gi; > > #Resulting String wanted: > Why are we here? To bless, inspire and uplift one another. > > The method I'm using above works and we get the results wanted but I was > looking at it again and I think there's a better way to do this. Any > suggested would be appreciated. > > Thx's > Mike(mickalo)Blezien > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > Thunder Rain Internet Publishing > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-