I need a regex that finds values other than !#!
in a string.
If, for example, the string were:
Text1!#!Text2!#!Text#3!#!
it should return Text1
, Text2
, Text#3
[^!#!]
would match the #
in Text#3
as well, which I don't want.
I need a regex that finds values other than !#!
in a string.
If, for example, the string were:
Text1!#!Text2!#!Text#3!#!
it should return Text1
, Text2
, Text#3
[^!#!]
would match the #
in Text#3
as well, which I don't want.
You could solve this problem using positive lookbehind and lookahead.
Simply:
(.+?)
(?<=^|!#!)
(?=!#!|$)
See your example here: https://rubular.com/r/f6BDr9CxeaQTIz using (?<=^|!#!)(.+?)(?=!#!|$)
You can use REGEXP_SUBSTR
in conjunction with CONNECT_BY
to split the string into words separated by !#!
. We use the regex:
(.*?)(!#!|$)
which matches some number of characters lazily until it encounters either !#!
or the end of string ($
).
For example:
SELECT REGEXP_SUBSTR ('Text1!#!Text2!#!Text#3!#!',
'(.*?)(!#!|$)',
1,
LEVEL,
'',
1)
AS VAL
FROM DUAL
CONNECT BY REGEXP_SUBSTR ('Text1!#!Text2!#!Text#3!#!',
'(.*?)(!#!|$)',
1,
LEVEL,
'',
1)
IS NOT NULL
Output:
VAL
Text1
Text2
Text#3