[英]Regex: regex match everything but specific pattern
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
它应该返回
Text1
, Text2
, Text#3
[^!#!]
would match the #
in Text#3
as well, which I don't want. [^!#!]
也会匹配Text#3
中的#
,这是我不想要的。
You could solve this problem using positive lookbehind and lookahead.您可以使用积极的后视和前瞻来解决这个问题。
Simply:简单地:
(.+?)
(.+?)
(?<=^|!#!)
(?<=^|!#!)
(?=!#!|$)
(?=!#!|$)
See your example here: https://rubular.com/r/f6BDr9CxeaQTIz using (?<=^|.#?)(?+?)(?=!#!|$)
在此处查看您的示例: https://rubular.com/r/f6BDr9CxeaQTIz使用
(?<=^|.#?)(?+?)(?=!#!|$)
You can use REGEXP_SUBSTR
in conjunction with CONNECT_BY
to split the string into words separated by !#!
您可以将
REGEXP_SUBSTR
与CONNECT_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: Output:
VAL
Text1
Text2
Text#3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.