September 30th, 2009, 07: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?
October 1st, 2009, 12:28 AM
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, 03: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, 04: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 04:30 PM.