如何组合以下正则表达式

How to combine the following regex?

本文关键字:正则表达式 组合 何组合      更新时间:2023-09-26

所以基本的想法是我想将以下内容分为 3 个部分,描述文本、html 代码和脚本代码:

---
name: Accordion
description: |
  ### What
  Puts modules of content into a linear stack of panels that can be closed and opened independently of each other. The accordion also helps in shortening a page and making it more scannable.
  ### Use when
  The content modules are mutually exclusive. Content modules can consist of a list of items, links or text blocks. 
---
<!-- Accordion-->
<div class="ui-accordion">
    some html
</div>
<!-- / Accordion  -->
<script>
some code
</script>

目前我已经能够将其分为两部分,但它还包括需要在第三部分中的脚本部分。

^(-{3}(?:'n|'r)(['w'W]+?)-{3})?(['w'W]*)

我试过这种方式,但没有工作

^(-{3}(?:'n|'r)(['w'W]+?)-{3})?(['w'W]*)(<script.*?>(['s'S]*?)<'/script>)

有什么建议吗?

我需要的确切输出如下:

### What
      Puts modules of content into a linear stack of panels that can be closed and opened independently of each other. The accordion also helps in shortening a page and making it more scannable.
      ### Use when
      The content modules are mutually exclusive. Content modules can consist of a list of items, links or text blocks. 
<!-- Accordion-->
<div class="ui-accordion">
    some html
</div>
<!-- / Accordion  -->
some code

但它需要分为 3 组。

试试这个:

(?:---['s'n'r]*((?:.|['n'r's])*)(?=['s'r'n]+---)['s'r'n]+---)?(?:(?=['n'r's]+<!--['s]*Accordion['s]*-->)['s'r'n]+<!--['s*]Accordion['s]*-->['s'n'r]*((?:.|['n'r's])*)(?=['s'r'n]*<!--['s]*'/ Accordion['s]*-->)['s'r'n]+<!--['s]*'/ Accordion['s]*-->)?(?:(?:.|['n'r's])*(?=<script>)<script>['s'r'n]*((?:.|['n'r's])*)(?=['s'r'n]*<'/script>)['s'r'n]+<'/script>)?

请注意,这严格限于输入中的一些内容(注释用"---"包装,注释以 开头/结尾)。可能需要进行调整以适应更自由的比赛。