我试图拆分一个包含两个复合分隔符和嵌套分隔符的字符串:
~|^|问题是regex模式在单个分隔符(如:~或| )上工作,或者它也适用于复合分隔符(如~~或^^ ),但它不适用于上述分隔符。
目标字符串:
*~~36415^^Description^^Version-4~~70450^^Description2^^Version-4~~73110^^Description3^^Version-4~~73140*使用的Regex:* [^(~|)]* * [^(~\|)]* * ((?!((~)(\|))).) * (?!(~\|).)
但没起作用。但是,当我将目标字符串更改为:
36415^^MRI Orbit, Face, Neck W W/O Contrast^^CPT-4~~70450^^MRI Orbit, Face, Neck W W/O Contrast^^CPT-4~~73110^^MRI Orbit, Face, Neck W W/O Contrast^^CPT-4~~73140并使用regex:* [^(~~)]* * [^(^^)]*
它起作用了。
P.S.:我用https://regex101.com/r/Stbwxt/1来测试这个。
WITH String_splits AS (
SELECT TRIM(',' FROM REGEXP_SUBSTR('~|36415^|Description^|Version-4~|70450^|Description2^|Version-4~|73110^|Description3^|Version-4~|73140', '[^(~|)]*', 1, LEVEL)) String_splits_1
, TRIM(',' FROM REGEXP_SUBSTR('~|36415^|Description^|Version-4~|70450^|Description2^|Version-4~|73110^|Description3^|Version-4~|73140', '[^(~|)]*', 3, LEVEL)) String_splits_2
FROM dual
CONNECT BY LEVEL <= REGEXP_COUNT('~|36415^|Description^|Version-4~|70450^|Description2^|Version-4~|73110^|Description3^|Version-4~|73140', '[^(~|)]*')
)
SELECT String_splits_1
, String_splits_2
FROM String_splits;发布于 2019-04-12 21:06:52
我不知道初始输入字符串是什么;我希望这是一个。像这样的事有意义吗?这样做的目的是:用不同的(例如分号)替换当前的分隔符,然后将字符串拆分成行。
SQL> with test (col) as
2 (select '~|36415^|Description^|Version-4~|70450^|Description2^|Version-4~|73110^|Description3^|Version-4~|73140'
3 from dual
4 ),
5 t_replaced as
6 (select replace(replace(col, '~|', ';'), '^|', ';') rep
7 from test
8 )
9 select regexp_substr(rep, '[^;]+', 1, level) result
10 from t_replaced
11 connect by level <= regexp_count(rep, ';') + 1;
RESULT
--------------------------------------------------------------------------------
36415
Description
Version-4
70450
Description2
Version-4
73110
Description3
Version-4
73140
11 rows selected.
SQL>https://stackoverflow.com/questions/55659045
复制相似问题