Regex_replace仅检查1个实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Regex_replace仅检查1个实例相关的知识,希望对你有一定的参考价值。
您好如何创建一个正则表达式,该模式应该只有1个实例“
例如:
1. STRING"
2. "STRING
3. STRI"NG
4. STRING""
5. "STRING"
结果:
1. STRING""
2. ""STRING
3. STRI""NG
4. STRING"" (No change since 2 instance of ")
5. "STRING" (No change since 2 instance of ")
答案
像这样的东西:
with t as (
select 'STRING"' as s from dual union all
select '"STRING' from dual union all
select 'STRI"NG' from dual union all
select 'STRING""' from dual union all
select '"STRING"' from dual union all
select 'STRING' from dual union all
select '"STR"ING"' from dual union all
select '"' from dual union all
select '""' from dual union all
select '"""' from dual
)
select
s,
regexp_replace(s,'^([^"]*)"([^"]*)$', '1""2') new_s
from t
输出:
+-----------+-----------+
| S | NEW_S |
+-----------+-----------+
| STRING" | STRING"" |
| "STRING | ""STRING |
| STRI"NG | STRI""NG |
| STRING"" | STRING"" |
| "STRING" | "STRING" |
| STRING | STRING |
| "STR"ING" | "STR"ING" |
| " | "" |
| "" | "" |
| """ | """ |
+-----------+-----------+
说明:
^ # asserts position at start of a line
( # 1st capturing group
[^"]* # matches characters that are not the character ", zero or more times
)
" # matches the character " literally
( # 2nd capturing group
[^"]*
)
$ # asserts position at the end of a line
使用rextester在线查看。
以上是关于Regex_replace仅检查1个实例的主要内容,如果未能解决你的问题,请参考以下文章