Hi All. Any gurus at EE’s interpretation of regex (specifically as it applies to the :replace
variable modifier)? I am trying to replace the last character of lines of this type with a semi-colon.
('293','10','292','7','1'), ('293','10','292','7','2'), ('293','11','292','8','1'), ('293','11','292','8','2'),
In VSC (and checked via regex101.com) this pattern matches all but the last character of the line : /(.*)./
and so the substitution pattern $1;
gives the revised line I am after.
When I apply these patterns via the :replace
modifier (i.e.
{value_to_update:replace find='/(.*)./' replace='$1;' regex='yes'}
EE replaces all the commas after )
with semi colons - so I end up with
('293','10','292','7','1'); ('293','10','292','7','2'); ('293','11','292','8','1'); ('293','11','292','8','2');
Does anyone have any hints as to how I can change the regex to get the outcome I want?
ExpressionEngine just passes your “find” pattern on to PHP’s preg_replace()
, which on your source string works as expected. I suspect your input is not what you think it is, and that instead of a space after the commas you have a newline. Which causes the pattern to only match each line, thus replacing all the commas with semicolons. If that’s the case, you can either address the input if it’s stored improperly, or just use the s
pattern modifier to ensure dots also match newline characters, e.g. /(.*)./s
See here.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.