Answer the question
In order to leave comments, you need to log in
How to get all characters before / using regular expressions?
In postgresql, there was a need to receive a string, or a part of a string before /, containing only numbers.
I've been struggling with the problem for a couple of hours now and can't solve it.
Lines can be of the form "1235", "1234/12", "dfhdhj1232", "dfhdhj1232/12"
From these lines I need to get
"1235", "1234", "not valid", "not valid" respectively.
In this example, everything works fine if / is present, when it is not, the expression returns null.
select substring('123405/99' from '#"%[0-9]#"/%' for '#')
select substring('123405/99' from '#"%[0-9]#"/?%' for '#')
select substring('123405/99' from '^(?=1)([0-9]{1,2})' for '#')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question