2015-01-16 2 views
0

그래서 기본적인 아이디어는 내가 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> 

은 현재 내가 2 개 부분으로 분할 할 수있었습니다 만 그것은 또한 세 번째 부분에 있어야하는 스크립트 섹션을 포함합니다.

^(-{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 개 그룹으로 분리 될 필요가있다 : 내가 필요

정확한 출력은 다음과 같다.

+0

왜'<-/Accordion ->'을 사용하지 않습니까? –

+1

예제 입력에서 원하는 정확한 출력을 포함하면 도움이됩니다. – forgivenson

+0

정확한 출력 추가 –

답변

0

이 시도 :이 (의견은, "---"로 주석의 시작/끝을 감싸도록) 입력에 몇 가지 엄격한 것을

(?:---[\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>)? 

참고. 좀 더 진보적 인 성냥에 맞게 조정해야 할 수도 있습니다.

관련 문제