Regexp_SUBSTR on an array returning no value [message #597175] |
Tue, 01 October 2013 08:02 |
|
caippers
Messages: 6 Registered: October 2013 Location: Des Moines
|
Junior Member |
|
|
I'm trying to query an array where we will have mathnames that have the follow format:
variablemathname[00000]
I'm new to regular expresions and have been digging around for a few days to try and simplify my existing query. As of right now i'm hacking it together to bring back the bracketed array value by using INSTR and SUBSTR. This works and gets me the correct results but I want to clean the code up by using regexp_SUBSTR.
In my reading up on regular expression I've tried to create my pattern by using [.] which I believe to be [any character]. I want it to start at the beginning of the string so I've used [^ and I only want the one occurrence so I've ended my expression with ]
I tried using the escape \ before my pattern as I know that [ is a metacharacter but I receive the same results.
Here is my query right now that i'm trying to use to get the expression correct.
SELECT REGEXP_SUBSTR('variablemathname[00000]', '[.],[^,],') RESULT
FROM DUAL;
My expectation is it will bring back the following [00000] but the way it is written now is bringing back nothing.
I would appreciate any insight.
|
|
|
|
|
Re: Regexp_SUBSTR on an array returning no value [message #597194 is a reply to message #597186] |
Tue, 01 October 2013 09:13 |
|
Michel Cadot
Messages: 68647 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
I didn't see you posted your query.
"[.]": any character, it is the same thing than just a single .
"," a comma
"[^,]" not a comma
so
"[.],[^,]," any character followed by a comma followed by any character but a comma followed by a comma.
For instance, "M,C,"
As this pattern does not exist in your string, it returns NULL.
For my pattern "\[[^\]*\]":
"\[" an open square bracket (protected by \ as it is a key character for pattern matching)
"[^\]]" any character that is not a close square bracket \] (protected for the same reason)
"[^\]*" any string (maybe empty one) that does not contain ]
"\]" a close square bracket
so "\[[^\]*\]" means an open square bracket followed by any number of characters up to the first close square bracket.
|
|
|
|
|
|
|
|
|
|