I'm trying to extract 456
from the string :123:456:
as follows:
select regexp_substr(':123:456:', ':(\d+):', 1, 2, 'i', 1) from dual
However, this query returns null
. What am I doing wrong?
András Váczi
31.8k13 gold badges103 silver badges152 bronze badges
asked Sep 5, 2012 at 16:14
2 Answers 2
This works fine:
select regexp_substr(':123:456:', '(\d+):', 1, 2, 'i', 1) from dual;
I think yours fails because the opening and closing colons won't get matched by both occurrences (because the first match is greedy).
answered Sep 5, 2012 at 16:43
select regexp_substr(':123:456:','[^:]+',2,2) from dual
Aaron Bertrand
182k28 gold badges407 silver badges626 bronze badges
-
1If this is substantially different from the accepted answer posted by Phil 10 months ago, please add some context explaining why.Aaron Bertrand– Aaron Bertrand2013年07月09日 13:58:14 +00:00Commented Jul 9, 2013 at 13:58
-
This will match on
:123:abc:
which doesn't sound desirable, but fail to match on::456:
which might be.Mat– Mat2013年07月09日 17:03:27 +00:00Commented Jul 9, 2013 at 17:03
Explore related questions
See similar questions with these tags.
lang-sql