September 30th, 2009, 06:12 PM
Remove all chars except anything in the quotes.
Hi this sounds easy but I can't get it to work.
I want to remove all chars from the following string:
and be left with
So far I have been able to remove define(' but nothing else. everything I try breaks.
This is the regex so far:
Its in perl
Anyone wanna help?
September 30th, 2009, 11:28 PM
Think replace, not remove.
My Perl's a bit weak - that should get you most of the way.
s/^define\('([^']+)', '([^']+)'\);/$1, $2/g;
Comments on this post
October 1st, 2009, 02:14 AM
Hi thanks for the reply.
Originally Posted by requinix
I couldn't get your example work however I took a differant approch and done this:
I think my problem was that I wasn't breaking down the string into separate parts
$re4='((?:[a-z][a-z]+))'; # Word 1
$re6='((?:[a-z][a-z]+))'; # Word 2
if ($txt =~ m/$re/is)
print "($word1) ($word2) \n";
October 1st, 2009, 03:19 PM
requinix' suggestion works like a charm!
$text = "define('NAME', 'VALUE');";
$text =~ s/^define\('([^']+)', '([^']+)'\);/$1, $2/g;
Last edited by prometheuzz; October 1st, 2009 at 03:30 PM.