I’m trying to find a way to replace spaces and double quotes with pipes (||) while leaving the spaces within the double quotes untouched.
For example, it would make something like ‘word “word word” word’ into ‘word||word word||word’ and another like ‘word word word’ into ‘word||word||word’.
Right now I have this to work off of:
[%- MACRO typestrip(value) PERL -%]
my $htmlVal = $stash->get('value');
$htmlVal =~ s/"/||/g;
print $htmlVal
[%- END -%]
Which handles replacing double quotes with pipes just fine.
I don’t know how simple or complex this should be or if it can even be done, since I have no actual background in programming and, while I have worked with some Perl, it’s never been this kind before, so I apologize if I’m not doing a good job of explaining this.
Seems possible and might be useful if only a regex is applicable:
(Might be beautified a bit after closer introspection.)
input:
output:
Original code has been modified after failing this case:
will now work too:
Explanation:
Regards
rbo