이 http://regex101.com/r/aT8yM3/4 예에서 "Title1"키와 일치시키고 싶습니다.첫 번째 일치 조건에서 욕심이 많은 정규식을 올바르게 끊는 방법?
Case1 1: Delimited with an empty line
***************************************
* Some preambule...
* Title1 : Some multi-line text
* Here the second line
* Title2 : Some other text
***************************************
Case1 2: Delimited an empty line
***************************************
* Some preambule...
* Title1 : Some multi-line text
* Here the second line
*
* Title2 : Some other text
***************************************
Case1 3: Delimited with a separator
***************************************
* Some preambule...
* Title1 : Some multi-line text
* Here the second line
***************************************
두 경우 모두를 위해 나는이 문자열을 얻어야한다 : 내가 사용
Some multi-line text
* Here the second line
정규식은 다음과 같습니다 예상대로
/
^.*?Title1\s*:\s* # I want to get the key "Title1"
((?:\n|.)+?) # Which can be a multi-line string
^(?:
.*Title2\s*:(*SKIP) # Until the line that contains 'Input : '
|
[^*]\*\n(*SKIP) # Or until the a blank line
|
^[^*]\*+(*SKIP) # Or until a separator
)
/gmx
불행하게도 그것이 작동하지 않습니다. 구조 같습니다
(cond1|cond2|cond3)
모든 조건을 평가합니다. (*SKIP)
또는 (*PRUNE)
과 같은 첫 번째 성공적인 조건에서 정규식을 해독하고 싶습니다.하지만이를 수행 할 방법을 찾지 못했습니다.
(?|
^.*?Title1\s*:\s* # I want to get the key "Title1"
((?:\n|.)+?) # Which can be a multi-line string
^.*Title2\s*: # Until the line that contains 'Input : '
|
^.*?Title1\s*:\s* # I want to get the key "Title1"
((?:\n|.)+?) # Which can be a multi-line string
^[^*]\*\n # Or until the a blank line
|
^.*?Title1\s*:\s* # I want to get the key "Title1"
((?:\n|.)+?) # Which can be a multi-line string
^[^*]\*+ # Or until a separator
)
이유는 다음과 같은'*'후'...'를 캡처 싶지 않아? –
@AvinashRaj 문제가되지 않습니다. 캡처 할 수 있습니다. – nowox
http://regex101.com/r/aT8yM3/2? –