[MDEV-24987] Regexp Look-ahead is working without a fixed-length regexp Created: 2021-02-25  Updated: 2021-03-09  Resolved: 2021-03-09

Status: Closed
Project: MariaDB Server
Component/s: Documentation
Affects Version/s: 10.5.5
Fix Version/s: N/A

Type: Bug Priority: Trivial
Reporter: Christian Proust Assignee: Ian Gilfillan
Resolution: Fixed Votes: 0
Labels: documentation


 Description   

In the PCRE page, it is written:

Note that look-ahead and look-behind assertions can only be of fixed length; you cannot have repetition operators or alternations with different lengths

It is true that for a look-behind, the pattern should have a fixed-length. However, for a look-ahead, this is not requested.

More information from PERL documentation.

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;

Returns:

(''),
('BB'),
('R2')


Generated at Thu Feb 08 09:34:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.