Tola, , , . , , "regex-match pattern, ..."
, ( |), , , ... | , , 1. 1, , .
?
-, , unwanted outer-start inner-start. :
outer-start(?:(?!inner-start).)*?unwanted.*?outer-end
|. .
-, , unwanted inner-end outer-end. :
outer-start(?:(?!outer-end).)*?inner-end(?:(?!outer-end).)*?unwanted.*?outer-end
|. , , "" *? .
-, , . :
inner-start\s*(text-that-i-want)\s*inner-end
, :
(?xs)
outer-start(?:(?!inner-start).)*?unwanted.*?outer-end
|
outer-start(?:(?!outer-end).)*?inner-end(?:(?!outer-end).)*?unwanted.*?outer-end
|
inner-start\s*(text-that-i-want)\s*inner-end
, 1 : , , .
In Perl and PCRE (used, for example, in PHP) you don’t even need to look at group 1: you can make the regular expression skip two blocks that we don’t need. The regular expression becomes:
(?xs)
(?:
outer-start(?:(?!inner-start).)*?unwanted.*?outer-end
|
outer-start(?:(?!outer-end).)*?inner-end(?:(?!outer-end).)*?unwanted.*?outer-end
)
(*SKIP)(*F)
|
inner-start\s*\Ktext-that-i-want(?=\s*inner-end)
See the demo : it directly matches what you want.
This method is explained in detail in the question and article below.
Link