In textmate:
search: ((?:---(?>[^-]++|-(?!--))*---|\G(?<!\A))(?>[^&]++|&(?!#8217;))*)’
replace: $1'
pattern details:
( # capture group 1: all possible content before ’
(?: # non capturing group: possible "anchors"
--- # begining of the header: entry point
(?> # atomic group: possible content of the header
[^-]++ # all that is not a -
| # OR
-(?!--) # a - not followed by --
)* # repeat the atomic group zero or more times
--- # end of the header
| # OR
\G(?<!\A) # contiguous to a precedent match (not at the start)
) # close the non capturing group
(?> # atomic group: all that is not ’
[^&]++ # all character except &
| # OR
&(?!#8217;) # & not followed by #8217;
)* # repeat the atomic group zero or more times
) # close the capturing group
’
The idea is to use the \G
feature to allow only contiguous matches.
First match: The entry point is the header. Once the header is found (first possibility, in the non capturing group), the pattern match all that is not ’
(second atomic group) until ’
.
Other matches: \G
forces the other matches to be contiguous to the precedent. The second match start at the first match end, the third at the second end, etc.