I was trying to make a Regex to extract some information with the SUBSTRING function, but the REGEX that I've tried on https://regex101.com/r/cFy11t/1 return an error on postgresql : "quantifier operand invalid"
The goal of this substring is to extract the last number in the string, and include complement as "A, B... G, or BIS, TER" if the number is like "12B of street X". If several numbers are in the string, it should pick the last one, except if the last one is at the end of the string.
For example, in the string "123 47F ABC 33 BIS", the result should be "47F"
I've already changed a lot the code since I wasn't getting the expected output, but I only get an error since I've forced the greedy quantifier "++" and "?+" to get the letter if possible
So here is the last version of my code where postgres raise an error: (but you can click on the link up to see it with color it might be more clear)
SELECT SUBSTRING(Adresse, '(\d++((?:\s)?([A-G]|BIS|TER|QUARTER)?+\s)(?!$))(?!(.*\d+(\s)?[A-G]?+\D))') Numero,
...
Thank you for your time !
'^(?:.*\D)?(\d+(?!\s?(?:BIS|TER|QUARTER|[A-G])$)\s?(?:BIS|TER|QUARTER|[A-G])?\y)'in PostgreSQL (it won't work at regex101). Or,'^.*\y(\d+(?!\s?(?:BIS|TER|QUARTER|[A-G])$)\s?(?:BIS|TER|QUARTER|[A-G])?\y)'might do, too.