Comments - REGEXP_SUBSTR

3 years, 6 months ago Christian Proust

There is one work-around. You can use \K and (?=) to look-ahead and look-behind your subject.

For example:

WITH log(X) AS (
	VALUES
	-- 'over' does not match because 'cute' does not end with a digit
	('Do you know the droid? It is over-cute <3'),
	('I think it is BB-8.'),
	-- 'BB' does not match because it is preceded by 'not'.
	('No it is not BB-8. It is R2-D2.')
)
-- Search a word preceding by 'is ' and followed by '-\\w*\\d'
SELECT REGEXP_SUBSTR(X, 'is \\K\\w+(?=-\\w*\\d)')
FROM log;
-> ''
-> 'BB'
-> 'R2'
 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.