如果超过一组匹配(多个 XOR),则 Reg Exp 不选择

发布于 2025-01-09 21:12:37 字数 3091 浏览 1 评论 0原文

数据保存在 Oracle 12c 数据库中,每个 ICD-10-CM 代码一行,带有患者 ID(外键),如下所示(请注意,可能还有许多其他代码,以下只是与此问题相关的代码) ):

ID   ICD10CODE
 1   S72.91XB
 1   S72.92XB
 2   S72.211A
 3   S72.414A
 3   S72.415A
 4   S32.509A
 5   S32.301A
 5   S32.821A
 6   S32.421A
 6   S32.422A
 7   S32.421A
 8   S32.421A
 8   S32.509A

当前的任务是选择仅匹配以下点之一的不同患者(使用标准正则表达式语法):

  • 任意数量:S32\.1\w\w\ w, S32\.2\w\w\wS32\.3\w\w\wS32\.5\w\w\w< /code>, S32\.6\w\w\w, S32\.7\w\w\w, S32\.8\w\ w\w
  • 任意数量: S32\.4\w1\wS32\.4\w3\wS32\.4\w4\w>S32\.4\w6\wS32\.4\w7\wS32\.4\w8\wS32\.4\w9\w
  • 任意数量:S32\.4\w2\wS32\.4\w3\w , S32\.4\w5\w, S32\.4\w6\w, S32\.4\w7\w, S32\.4\w8\wS32\.4\w9\w
  • 任意数量:S72\.[0-8]\w1\w, S72\.[0-8]\w3\w, S72\.[0-8]\w4\w, S72\.[0-8]\w6\wS72\.[0-8]\w7\wS72\.[0-8 ]\w8\wS72\.[0-8]\w9\w
  • 任意数量:S72\.[0-8]\w2\w代码>, S72\.[0-8]\w3\wS72\.[0-8]\w5\wS72\.[0-8 ]\w6\wS72\.[0-8]\w7\wS72\.[0-8]\w8\wS72\.[0-8]\w9\w
  • 任意数量:S72\.91\w\wS72\.93\w\wS72\.94\w\wS72\.96\w\wS72\.97\w\w代码>, S72\.98\w\wS72\.99\w\w
  • 任意数量:S72\.92\w\w , S72\.93\w\w, S72\.95\w\w, S72\.96\w\w, S72\.97\w\wS72\.98\w\wS72\.99\w\w

任何排列或每个患者允许对项目符号中列出的代码进行组合(包括重复),但跨行的排列或组合对于患者来说应该是互斥的。我的方法是在GROUP BY ID上应用LISTAGG

ID  LISTAGG(ICD10CODE, ',')
 1  S72.91XB,S72.92XB
 2  S72.211A
 3  S72.414A,S72.415A
 4  S32.509A
 5  S32.301A,S32.821A
 6  S32.421A,S32.422A
 7  S32.421A
 8  S32.421A,S32.509A

然后使用这个正则表达式进行过滤, <代码>(S32\.(([1-3]|[5-8])|(4\w((1|4)|(2|5)|(3)|([5-9]) )))\w+)|(S72\.(([0 -8]\w((1|4)|(2|5)|(3)|([5-9])))|(9((1|4)|(2|5)|(3) |([5-9]))))\w+),这几乎是上面项目符号的字面表示。我的表达是根据这个答案中的想法改编的,看起来,((RB\s+)+ |(JJ\s+)+) 自动选择 "RB""JJ",但不会同时选择两者。

我无法让它工作。答案应该只包含 ID 2、4、5 和 7。但是,我开发的表达式匹配所有 ID。

解决这个问题的办法是什么?


[编辑]更多信息:

以上所有这些 S 代码都与下肢骨骼损伤有关:S32 用于骨盆(髋骨)骨折,S72用于股骨(大腿骨)骨折。请注意,我们有两个股骨和两个髋臼(股骨连接的骨盆窝)。 S32.4 代码表示髋臼(S32.[1235678]\w{3} 系列的其余部分表示骨盆的其他部分)。左右股骨和髋臼分别用第 6 个字符中的 1|42|5 表示,除非代码以 S72.9 当这些数字出现在第 5 个字符时。

纳入研究人群的患者应该只有其中一根骨头骨折。这意味着,两根股骨之一、髋臼之一或骨盆,但不是它们的组合。单根骨头骨折的组合并不重要。例如,右侧单股骨可以在 10 个不同的位置和方式(膝盖区域、中轴、头部等)断裂,每个位置都会生成不同的 S72。\w[1|4]\w{ 2} 代码),并且仍应被选中。

The data are held in an Oracle 12c database, one row per ICD-10-CM code, with a patient ID (foreign key) like so (note that there could be many other codes, the following are just the ones pertinent to this question):

ID   ICD10CODE
 1   S72.91XB
 1   S72.92XB
 2   S72.211A
 3   S72.414A
 3   S72.415A
 4   S32.509A
 5   S32.301A
 5   S32.821A
 6   S32.421A
 6   S32.422A
 7   S32.421A
 8   S32.421A
 8   S32.509A

The task at hand is to select distinct patients that match only one of the following points (using standard regular expression syntax):

  • Any number of: S32\.1\w\w\w, S32\.2\w\w\w, S32\.3\w\w\w, S32\.5\w\w\w, S32\.6\w\w\w, S32\.7\w\w\w, S32\.8\w\w\w
  • Any number of: S32\.4\w1\w, S32\.4\w3\w, S32\.4\w4\w, S32\.4\w6\w, S32\.4\w7\w, S32\.4\w8\w, S32\.4\w9\w
  • Any number of: S32\.4\w2\w, S32\.4\w3\w, S32\.4\w5\w, S32\.4\w6\w, S32\.4\w7\w, S32\.4\w8\w, S32\.4\w9\w
  • Any number of: S72\.[0-8]\w1\w, S72\.[0-8]\w3\w, S72\.[0-8]\w4\w, S72\.[0-8]\w6\w, S72\.[0-8]\w7\w, S72\.[0-8]\w8\w, S72\.[0-8]\w9\w
  • Any number of: S72\.[0-8]\w2\w, S72\.[0-8]\w3\w, S72\.[0-8]\w5\w, S72\.[0-8]\w6\w, S72\.[0-8]\w7\w, S72\.[0-8]\w8\w, S72\.[0-8]\w9\w
  • Any number of: S72\.91\w\w, S72\.93\w\w, S72\.94\w\w, S72\.96\w\w, S72\.97\w\w, S72\.98\w\w, S72\.99\w\w
  • Any number of: S72\.92\w\w, S72\.93\w\w, S72\.95\w\w, S72\.96\w\w, S72\.97\w\w, S72\.98\w\w, S72\.99\w\w

Any permutation or combination (including repetitions) of codes listed within a bullet are permitted for each patient, but permutations or combinations across rows should occur mutually exclusively for a patient. My method is to apply LISTAGG on GROUP BY ID:

ID  LISTAGG(ICD10CODE, ',')
 1  S72.91XB,S72.92XB
 2  S72.211A
 3  S72.414A,S72.415A
 4  S32.509A
 5  S32.301A,S32.821A
 6  S32.421A,S32.422A
 7  S32.421A
 8  S32.421A,S32.509A

Then filter using this regular expression, (S32\.(([1-3]|[5-8])|(4\w((1|4)|(2|5)|(3)|([5-9]))))\w+)|(S72\.(([0-8]\w((1|4)|(2|5)|(3)|([5-9])))|(9((1|4)|(2|5)|(3)|([5-9]))))\w+), which is almost a literal representation of the bullets above. My expression is adapted from the idea in this answer, where it seems that, ((RB\s+)+|(JJ\s+)+) automatically selects either "RB" or "JJ", but not both.

I cannot get it to work. The answer should contain only IDs 2, 4, 5, and 7. But, the expression I developed matches all IDs.

What is a solution to this problem?


[Edit] Some more information:

All these S codes above relate to injuries to the bones in the lower extremity: S32 is for fractures of the pelvis (hip bone), S72 is for fractures of the femur (thigh bone). Note that we have two femurs, and two acetabulum (socket of the pelvis where the femur connects). The S32.4 code denotes the acetabulum (the rest of the S32.[1235678]\w{3} series denotes other parts of the pelvis). Right and left femur and acetabulum are denoted by 1|4 or 2|5 in the 6th character, respectively, unless the code starts with S72.9 when those numbers appear in the 5th character.

The patients to be included in the study population should only have one of the bones broken. That means, one of the two femurs, one of the acetabulum, or the pelvis, but not a combination of them. Combinations of fractures of a single bone do not matter. For example, the right single femur can be broken in 10 different places and ways (the knee area, the middle shaft, the head, etc., each generating a different S72.\w[1|4]\w{2} code), and should still be selected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不忘初心 2025-01-16 21:12:37

选项 1:

您可以使用单个正则表达式来完成:

SELECT t.id,
       t.icd10codes
FROM   ( SELECT id,
                LISTAGG(icd10code, ',') WITHIN GROUP (ORDER BY icd10code)
                  AS icd10codes
         FROM   table_name
         GROUP BY id
       ) t
WHERE  REGEXP_LIKE(
         t.icd10codes,
             '^(S32\.[1235678]\w\w\w(,|$))+

对于您的示例数据:

CREATE TABLE table_name (ID, ICD10CODE) AS
SELECT 1, 'S72.91XB' FROM DUAL UNION ALL
SELECT 1, 'S72.92XB' FROM DUAL UNION ALL
SELECT 2, 'S72.211A' FROM DUAL UNION ALL
SELECT 3, 'S72.414A' FROM DUAL UNION ALL
SELECT 3, 'S72.415A' FROM DUAL UNION ALL
SELECT 4, 'S32.509A' FROM DUAL UNION ALL
SELECT 5, 'S32.301A' FROM DUAL UNION ALL
SELECT 5, 'S32.821A' FROM DUAL UNION ALL
SELECT 6, 'S32.421A' FROM DUAL UNION ALL
SELECT 6, 'S32.422A' FROM DUAL UNION ALL
SELECT 7, 'S32.421A' FROM DUAL UNION ALL
SELECT 8, 'S32.421A' FROM DUAL UNION ALL
SELECT 8, 'S32.509A' FROM DUAL;

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

CREATE TABLE matches (id, match) AS
SELECT 1, 'S32\.[1235678]\w\w\w'    FROM DUAL UNION ALL
SELECT 2, 'S32\.4\w[1346789]\w'     FROM DUAL UNION ALL
SELECT 3, 'S32\.4\w[2356789]\w'     FROM DUAL UNION ALL
SELECT 4, 'S72\.[0-8]\w[1346789]\w' FROM DUAL UNION ALL
SELECT 5, 'S72\.[0-8]\w[2356789]\w' FROM DUAL UNION ALL
SELECT 6, 'S72\.9[1346789]\w\w'     FROM DUAL UNION ALL
SELECT 7, 'S72\.9[2356789]\w\w'     FROM DUAL;

然后您可以使用查询:

SELECT t.id,
       m.id AS match_id,
       LISTAGG(t.icd10code, ',') WITHIN GROUP (ORDER BY t.icd10code)
         AS icd10codes
FROM   table_name t
       LEFT OUTER JOIN matches m
       PARTITION BY (m.id)
       ON (REGEXP_LIKE(t.icd10code, '^' || m.match || '

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

SELECT t.id,
       m.id AS match_id,
       t.icd10codes
FROM   ( SELECT id,
                LISTAGG(icd10code, ',') WITHIN GROUP (ORDER BY icd10code)
                  AS icd10codes
         FROM   table_name
         GROUP BY id
       ) t
       INNER JOIN matches m
       ON (REGEXP_LIKE(t.icd10codes, '^(' || m.match || '(,|$))+

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

CREATE TABLE matches (id, match) AS
SELECT 1, 'S32.1___' FROM DUAL UNION ALL
SELECT 1, 'S32.2___' FROM DUAL UNION ALL
SELECT 1, 'S32.3___' FROM DUAL UNION ALL
SELECT 1, 'S32.5___' FROM DUAL UNION ALL
SELECT 1, 'S32.6___' FROM DUAL UNION ALL
SELECT 1, 'S32.7___' FROM DUAL UNION ALL
SELECT 1, 'S32.8___' FROM DUAL UNION ALL
SELECT 2, 'S32.4_1_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_3_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_4_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_6_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_7_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_8_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_9_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_2_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_3_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_5_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_6_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_7_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_8_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_9_' FROM DUAL UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_1_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_3_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_4_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_6_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_7_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_8_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_9_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_2_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_3_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_5_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_6_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_7_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_8_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_9_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 6, 'S72.91__' FROM DUAL UNION ALL
SELECT 6, 'S72.93__' FROM DUAL UNION ALL
SELECT 6, 'S72.94__' FROM DUAL UNION ALL
SELECT 6, 'S72.96__' FROM DUAL UNION ALL
SELECT 6, 'S72.97__' FROM DUAL UNION ALL
SELECT 6, 'S72.98__' FROM DUAL UNION ALL
SELECT 6, 'S72.99__' FROM DUAL UNION ALL
SELECT 7, 'S72.92__' FROM DUAL UNION ALL
SELECT 7, 'S72.93__' FROM DUAL UNION ALL
SELECT 7, 'S72.95__' FROM DUAL UNION ALL
SELECT 7, 'S72.96__' FROM DUAL UNION ALL
SELECT 7, 'S72.97__' FROM DUAL UNION ALL
SELECT 7, 'S72.98__' FROM DUAL UNION ALL
SELECT 7, 'S72.99__' FROM DUAL;

则使用查询:

SELECT t.id,
       m.id AS match_id,
       LISTAGG(t.icd10code, ',') WITHIN GROUP (ORDER BY t.icd10code)
         AS icd10codes
FROM   table_name t
       LEFT OUTER JOIN matches m
       PARTITION BY (m.id)
       ON (t.icd10code LIKE m.match)
GROUP BY
       t.id,
       m.id
HAVING
       COUNT(m.match) = COUNT(t.id);

db<>fiddle 此处

|| '|^(S32\.4\w[1346789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S32\.4\w[2356789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.9[1346789]\w\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.9[2356789]\w\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

)

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

)) GROUP BY t.id, m.id HAVING COUNT(m.match) = COUNT(t.id);

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S32\.4\w[1346789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S32\.4\w[2356789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.9[1346789]\w\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

|| '|^(S72\.9[2356789]\w\w(,|$))+

对于您的示例数据:


输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:


然后您可以使用查询:


选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:


选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:


则使用查询:


db<>fiddle 此处

)

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

))

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S32\.4\w[1346789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S32\.4\w[2356789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.9[1346789]\w\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.9[2356789]\w\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

)

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

)) GROUP BY t.id, m.id HAVING COUNT(m.match) = COUNT(t.id);

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S32\.4\w[1346789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S32\.4\w[2356789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.9[1346789]\w\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

|| '|^(S72\.9[2356789]\w\w(,|$))+

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

)

对于您的示例数据:

输出:

<表类=“s-表”>
<标题>

ID
ICD10CODES


<正文>

2
S72.211A

4
S32.509A

5
S32.301A,S32.821A

7
S32.421A


选项 2:

您可以将正则表达式放入表中:

然后您可以使用查询:

选项 3:

与第一个选项类似,但您可以将匹配项放入表中,然后您可以确定使用了哪个匹配项:

选项 2 & 3. 两者输出:

<表类=“s-表”>
<标题>

ID
MATCH_ID
ICD10CODES


<正文>

4
1
S32.509A

5
1
S32.301A,S32.821A

7
2
S32.421A

2
4
S72.211A


选项 4:

您还可以摆脱(慢)正则表达式并使用 LIKE 如果将匹配项存储为:

则使用查询:

db<>fiddle 此处

Option 1:

You can do it with a single regular expression:

SELECT t.id,
       t.icd10codes
FROM   ( SELECT id,
                LISTAGG(icd10code, ',') WITHIN GROUP (ORDER BY icd10code)
                  AS icd10codes
         FROM   table_name
         GROUP BY id
       ) t
WHERE  REGEXP_LIKE(
         t.icd10codes,
             '^(S32\.[1235678]\w\w\w(,|$))+

Which, for your sample data:

CREATE TABLE table_name (ID, ICD10CODE) AS
SELECT 1, 'S72.91XB' FROM DUAL UNION ALL
SELECT 1, 'S72.92XB' FROM DUAL UNION ALL
SELECT 2, 'S72.211A' FROM DUAL UNION ALL
SELECT 3, 'S72.414A' FROM DUAL UNION ALL
SELECT 3, 'S72.415A' FROM DUAL UNION ALL
SELECT 4, 'S32.509A' FROM DUAL UNION ALL
SELECT 5, 'S32.301A' FROM DUAL UNION ALL
SELECT 5, 'S32.821A' FROM DUAL UNION ALL
SELECT 6, 'S32.421A' FROM DUAL UNION ALL
SELECT 6, 'S32.422A' FROM DUAL UNION ALL
SELECT 7, 'S32.421A' FROM DUAL UNION ALL
SELECT 8, 'S32.421A' FROM DUAL UNION ALL
SELECT 8, 'S32.509A' FROM DUAL;

Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:

CREATE TABLE matches (id, match) AS
SELECT 1, 'S32\.[1235678]\w\w\w'    FROM DUAL UNION ALL
SELECT 2, 'S32\.4\w[1346789]\w'     FROM DUAL UNION ALL
SELECT 3, 'S32\.4\w[2356789]\w'     FROM DUAL UNION ALL
SELECT 4, 'S72\.[0-8]\w[1346789]\w' FROM DUAL UNION ALL
SELECT 5, 'S72\.[0-8]\w[2356789]\w' FROM DUAL UNION ALL
SELECT 6, 'S72\.9[1346789]\w\w'     FROM DUAL UNION ALL
SELECT 7, 'S72\.9[2356789]\w\w'     FROM DUAL;

Then you can use the query:

SELECT t.id,
       m.id AS match_id,
       LISTAGG(t.icd10code, ',') WITHIN GROUP (ORDER BY t.icd10code)
         AS icd10codes
FROM   table_name t
       LEFT OUTER JOIN matches m
       PARTITION BY (m.id)
       ON (REGEXP_LIKE(t.icd10code, '^' || m.match || '

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

SELECT t.id,
       m.id AS match_id,
       t.icd10codes
FROM   ( SELECT id,
                LISTAGG(icd10code, ',') WITHIN GROUP (ORDER BY icd10code)
                  AS icd10codes
         FROM   table_name
         GROUP BY id
       ) t
       INNER JOIN matches m
       ON (REGEXP_LIKE(t.icd10codes, '^(' || m.match || '(,|$))+

Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

CREATE TABLE matches (id, match) AS
SELECT 1, 'S32.1___' FROM DUAL UNION ALL
SELECT 1, 'S32.2___' FROM DUAL UNION ALL
SELECT 1, 'S32.3___' FROM DUAL UNION ALL
SELECT 1, 'S32.5___' FROM DUAL UNION ALL
SELECT 1, 'S32.6___' FROM DUAL UNION ALL
SELECT 1, 'S32.7___' FROM DUAL UNION ALL
SELECT 1, 'S32.8___' FROM DUAL UNION ALL
SELECT 2, 'S32.4_1_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_3_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_4_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_6_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_7_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_8_' FROM DUAL UNION ALL
SELECT 2, 'S32.4_9_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_2_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_3_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_5_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_6_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_7_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_8_' FROM DUAL UNION ALL
SELECT 3, 'S32.4_9_' FROM DUAL UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_1_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_3_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_4_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_6_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_7_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_8_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 4, 'S72.' || (LEVEL - 1) || '_9_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_2_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_3_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_5_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_6_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_7_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_8_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 5, 'S72.' || (LEVEL - 1) || '_9_' FROM DUAL CONNECT BY LEVEL <= 9 UNION ALL
SELECT 6, 'S72.91__' FROM DUAL UNION ALL
SELECT 6, 'S72.93__' FROM DUAL UNION ALL
SELECT 6, 'S72.94__' FROM DUAL UNION ALL
SELECT 6, 'S72.96__' FROM DUAL UNION ALL
SELECT 6, 'S72.97__' FROM DUAL UNION ALL
SELECT 6, 'S72.98__' FROM DUAL UNION ALL
SELECT 6, 'S72.99__' FROM DUAL UNION ALL
SELECT 7, 'S72.92__' FROM DUAL UNION ALL
SELECT 7, 'S72.93__' FROM DUAL UNION ALL
SELECT 7, 'S72.95__' FROM DUAL UNION ALL
SELECT 7, 'S72.96__' FROM DUAL UNION ALL
SELECT 7, 'S72.97__' FROM DUAL UNION ALL
SELECT 7, 'S72.98__' FROM DUAL UNION ALL
SELECT 7, 'S72.99__' FROM DUAL;

Then use the query:

SELECT t.id,
       m.id AS match_id,
       LISTAGG(t.icd10code, ',') WITHIN GROUP (ORDER BY t.icd10code)
         AS icd10codes
FROM   table_name t
       LEFT OUTER JOIN matches m
       PARTITION BY (m.id)
       ON (t.icd10code LIKE m.match)
GROUP BY
       t.id,
       m.id
HAVING
       COUNT(m.match) = COUNT(t.id);

db<>fiddle here

|| '|^(S32\.4\w[1346789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S32\.4\w[2356789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.9[1346789]\w\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.9[2356789]\w\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

)

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

)) GROUP BY t.id, m.id HAVING COUNT(m.match) = COUNT(t.id);

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S32\.4\w[1346789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S32\.4\w[2356789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.9[1346789]\w\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

|| '|^(S72\.9[2356789]\w\w(,|$))+

Which, for your sample data:


Outputs:

ID ICD10CODES
2 S72.211A
4 S32.509A
5 S32.301A,S32.821A
7 S32.421A

Option 2:

You can put the regular expressions into a table:


Then you can use the query:


Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:


Options 2 & 3 both output:

ID MATCH_ID ICD10CODES
4 1 S32.509A
5 1 S32.301A,S32.821A
7 2 S32.421A
2 4 S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:


Then use the query:


db<>fiddle here

)

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

))

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S32\.4\w[1346789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S32\.4\w[2356789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.9[1346789]\w\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.9[2356789]\w\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

)

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

)) GROUP BY t.id, m.id HAVING COUNT(m.match) = COUNT(t.id);

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S32\.4\w[1346789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S32\.4\w[2356789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.[0-8]\w[1346789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.[0-8]\w[2356789]\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.9[1346789]\w\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

|| '|^(S72\.9[2356789]\w\w(,|$))+

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

)

Which, for your sample data:

Outputs:

IDICD10CODES
2S72.211A
4S32.509A
5S32.301A,S32.821A
7S32.421A

Option 2:

You can put the regular expressions into a table:

Then you can use the query:

Option 3:

Similar to the first option, but you can put the matches into a table and you can determine which match has been used:

Options 2 & 3 both output:

IDMATCH_IDICD10CODES
41S32.509A
51S32.301A,S32.821A
72S32.421A
24S72.211A

Option 4:

You can also get rid of the (slow) regular expressions and use LIKE if you store the matches as:

Then use the query:

db<>fiddle here

眼眸 2025-01-16 21:12:37

好的,我已经把你的断骨代码添加到了S32和S72系列中。
这就是真正需要做的一切。

请随意将 ,? 更改为 (,|$),但不要更改其他任何内容。
让我知道断骨代码是否正确。

  • S32\.\w[25]\w\w、S32.1\w\w\w、S32.2\w\w\w、S32.3\w\w\w、 S32.5\w\w\w、S32.6\w\w\w、S32.7\w\w\w、S32.8\w\w\w
  • S32\.\w[25]\w\w、S32.4\w1\w、S32.4\w3\w、S32.4\w4\w、S32.4\w6\ w、S32.4\w7\w、S32.4\w8\w、S32.4\w9\w
  • S32\.\w[25]\w\w、S32.4\w2\w、S32.4\w3\w、S32.4\w5\w、S32.4\w6\ w、S32.4\w7\w、S32.4\w8\w、S32.4\w9\w
  • S72\.\w[14]\w\w, S72.[0-8]\w1\w, S72.[0-8]\w3\w, S72.[0-8 ]\w4\w, S72.[0-8]\w6\w, S72.[0-8]\w7\w, S72.[0-8]\w8\w, S72.[0-8]\w9\w
  • S72\.\w[14]\w\w, S72.[0-8]\w2\w, S72.[0-8] \w3\w, S72.[0-8]\w5\w, S72.[0-8]\w6\w, S72.[0-8]\w7\w, S72.[0-8]\w8\w, S72.[0-8]\w9\w
  • <代码>S72\.[14]\w\w\w, S72.91\w\w 、S72.93\w\w、S72.94\w\w、S72.96\w\w、S72.97\w\w、S72.98\w\w、 S72.99\w\w
  • <代码>S72\.[14]\w\w\w、S72.92\w\w、S72.93\w\w、S72.95\w\w , S72.96\w\w, S72.97\w\w, S72.98\w\w, S72.99\w\w

新的正则表达式是

^((S32\.(\w[25]|[1-35-8]\w)\w\w,?)+|(S32\.(\w[25]\w|4\w[1346-9])\w,?)+|(S32\.(\w[25]\w|4\w[235-9])\w,?)+|(S72\.(\w[14]\w|[0-8]\w[1346-9])\w,?)+|(S72\.(\w[14]\w|[0-8]\w[235-9])\w,?)+|(S72\.([14]\w|9[1346-9])\w\w,?)+|(S72\.([14]\w|9[235-9])\w\w,?)+)$

https://regex101.com/r/OAHdCO/1

 ^ 
 (
    ( S32 \. ( \w [25] | [1-35-8] \w ) \w\w ,? )+
  | ( S32 \. ( \w [25] \w | 4 \w [1346-9] ) \w ,? )+
  | ( S32 \. ( \w [25] \w | 4 \w [235-9] ) \w ,? )+
  | ( S72 \. ( \w [14] \w | [0-8] \w [1346-9] ) \w ,? )+
  | ( S72 \. ( \w [14] \w | [0-8] \w [235-9] ) \w ,? )+
  | ( S72 \. ( [14] \w | 9 [1346-9] ) \w\w ,? )+
  | ( S72 \. ( [14] \w | 9 [235-9] ) \w\w ,? )+
 )
 $

Ok, I've added your broken bones codes to the S32 and S72 series.
That's all that needed to be done really.

Feel free to change ,? to (,|$) but don't change anything else.
Let me know if the broken bones codes is about right.

  • S32\.\w[25]\w\w, S32.1\w\w\w, S32.2\w\w\w, S32.3\w\w\w, S32.5\w\w\w, S32.6\w\w\w, S32.7\w\w\w, S32.8\w\w\w
  • S32\.\w[25]\w\w, S32.4\w1\w, S32.4\w3\w, S32.4\w4\w, S32.4\w6\w, S32.4\w7\w, S32.4\w8\w, S32.4\w9\w
  • S32\.\w[25]\w\w, S32.4\w2\w, S32.4\w3\w, S32.4\w5\w, S32.4\w6\w, S32.4\w7\w, S32.4\w8\w, S32.4\w9\w
  • S72\.\w[14]\w\w, S72.[0-8]\w1\w, S72.[0-8]\w3\w, S72.[0-8]\w4\w, S72.[0-8]\w6\w, S72.[0-8]\w7\w, S72.[0-8]\w8\w, S72.[0-8]\w9\w
  • S72\.\w[14]\w\w, S72.[0-8]\w2\w, S72.[0-8]\w3\w, S72.[0-8]\w5\w, S72.[0-8]\w6\w, S72.[0-8]\w7\w, S72.[0-8]\w8\w, S72.[0-8]\w9\w
  • S72\.[14]\w\w\w, S72.91\w\w, S72.93\w\w, S72.94\w\w, S72.96\w\w, S72.97\w\w, S72.98\w\w, S72.99\w\w
  • S72\.[14]\w\w\w, S72.92\w\w, S72.93\w\w, S72.95\w\w, S72.96\w\w, S72.97\w\w, S72.98\w\w, S72.99\w\w

The new regex is

^((S32\.(\w[25]|[1-35-8]\w)\w\w,?)+|(S32\.(\w[25]\w|4\w[1346-9])\w,?)+|(S32\.(\w[25]\w|4\w[235-9])\w,?)+|(S72\.(\w[14]\w|[0-8]\w[1346-9])\w,?)+|(S72\.(\w[14]\w|[0-8]\w[235-9])\w,?)+|(S72\.([14]\w|9[1346-9])\w\w,?)+|(S72\.([14]\w|9[235-9])\w\w,?)+)$

https://regex101.com/r/OAHdCO/1

 ^ 
 (
    ( S32 \. ( \w [25] | [1-35-8] \w ) \w\w ,? )+
  | ( S32 \. ( \w [25] \w | 4 \w [1346-9] ) \w ,? )+
  | ( S32 \. ( \w [25] \w | 4 \w [235-9] ) \w ,? )+
  | ( S72 \. ( \w [14] \w | [0-8] \w [1346-9] ) \w ,? )+
  | ( S72 \. ( \w [14] \w | [0-8] \w [235-9] ) \w ,? )+
  | ( S72 \. ( [14] \w | 9 [1346-9] ) \w\w ,? )+
  | ( S72 \. ( [14] \w | 9 [235-9] ) \w\w ,? )+
 )
 $
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文