Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?s)kMDItemContentTypeTree += +(.+?)(?=^[^ ]|\Z)
/
gm

Description

This uses the LookAhead feature to include match/capture of all text, either on a single line, or multiple lines, until it finds characters NOT in the "continuation" lines.

When a kMDItem uses multiple lines, it starts each continuation line with multiple SPACES. The start of a NEW kMDItem always starts with a NON-SPACE character, as in kMDItemCreator. This is true whether the kMDItem uses one line, or multiple lines.

The other trick is to use the \Z as an alternate, which will match the end of the text.

This LookAhead searches for any word character at the START of a line: (?=^\w|\Z)

Submitted by JMichaelTX - 8 years ago