I'm trying to replace multiple lines using the mariadb regex_replace
function.
CREATE TABLE `test` (
`entry` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `test` (`entry`) VALUES ('LINE1\r\nLINE2\r\nLINE3\r\nLINE4\r\nLINE5');
This creates one entry which the following content:
LINE1
LINE2
LINE3
LINE4
LINE5
Let's say I want to replace LINE2 through LINE4 with ''. This should be the result:
LINE1
LINE5
I've tried so many different regexes, but I'm out of ideas, as none of these work (no lines are removed).
select regexp_replace(entry, 'LINE2.*LINE4', '') from test
select regexp_replace(entry, 'LINE2[.\r\n]*LINE4', '') from test
select regexp_replace(entry, 'LINE2[.\R]*LINE4', '') from test
select regexp_replace(entry, '(*CRLF)LINE2.*LINE4', '') from test
select regexp_replace(entry, '(*ANYCRLF)LINE2.*LINE4', '') from test
I've also tried selecting using RLIKE
, but it also does not work (no entries returned):
select entry from test where entry RLIKE 'LINE1.*LINE4'
select entry from test where entry RLIKE '(*ANYCRLF)LINE1.*LINE5'
It should be possible, so I don't really know why this isn't working.
I'm using latest mariadb on debian (10.3.22).
To make sure this has nothing to do with the switch to PCRE2 in 10.5.1., I also check the historical mariadb pcre docs, but the syntax did not change.