您好如何创建一个正则表达式,该模式应该只有1个实例“
例如:
STRING“”2.“”STRING
像这样的东西:
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 。