On 10-07-13 06:00 AM, Bryan R Harris wrote:
I'm trying to temporarily deal with simple quoted strings by turning: data: "this is a string" more: "this is another" into... data: "this is a string" more: "this is another" I thought this would work: s/(['"])([^\1]*)\1/${1}.despace($2).$1/gse; sub despace { my $t = shift; $t =~ s/\s/ /g; return $t; } ... but it doesn't. It looks like the [^\1]* in the regex isn't working right. I can always split it into two, but I'm curious why the above doesn't work.
Because [] define a character set; everything inside it is a character. That means it does not expand \1.
Try: s/(['"])(.*?)\1/${1}.despace($2).$1/gse; This will set $2 to the minimum number of characters between the quotes. For details, see: perldoc perlretut perldoc perlre -- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early & often. Eliminate software piracy: use only FLOSS. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/