/
(?xsm) # free-spacing mode, DOTALL, multi-line
(?=.blue) # if blue isn't there, fail without delay
########### LINE SKIPPER / COUNTER ############
(?: # start non-capture group
# the aim is to skip lines that don't contain blue
# and capture a corresponding digit sequence
(?: # skip one line that doesn't contain blue
^ # beginning of line
(?:(?!blue)[^\r\n])* # zero or more chars
# that do not start blue
(?:\r\n) # newline chars
)
# With each line skipped, let Group 1 capture
# an ever-growing portion of the string of numbers
(?= # lookahead
. # Go to the end of the file
( # start Group 1
~\d # match a tilde and digits
(?(1)\1) # if Group 1 is set, match Group 1
) # end Group 1
) # end lookahead
)*+ # end counter-line-skipper: zero or more times
# the possessive + forbids backtracking
. # lazily match any chars up to...
blue # match blue
. # Get to the end of the data
~ # match a tilde
\K # drop what we matched so far
\d # match digits. This is the match!
(?=(?(1)\1)) # if Group 1 has been set, match it
/
(?xsm)
match the remainder of the pattern with the following effective flags: xsmx modifier: extended. Spaces and text after a # in the pattern are ignored
s modifier: single line. Dot matches newline characters
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Comment: free-spacing mode, DOTALL, multi-line
Positive Lookahead (?=.blue)
Assert that the Regex below matches
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
blue matches the characters blue literally (case sensitive)
Comment: if blue isn't there, fail without delay
Comment: ########## LINE SKIPPER / COUNTER ############
Non-capturing group (?: # start non-capture group
# the aim is to skip lines that don't contain blue
# and capture a corresponding digit sequence
(?: # skip one line that doesn't contain blue
^ # beginning of line
(?:(?!blue)[^\r\n])* # zero or more chars
# that do not start blue
(?:\r\n) # newline chars
)
# With each line skipped, let Group 1 capture
# an ever-growing portion of the string of numbers
(?= # lookahead
. # Go to the end of the file
( # start Group 1
~\d # match a tilde and digits
(?(1)\1) # if Group 1 is set, match Group 1
) # end Group 1
) # end lookahead
)*+
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
Comment: start non-capture group
Comment: the aim is to skip lines that don't contain blue
Comment: and capture a corresponding digit sequence
Non-capturing group (?: # skip one line that doesn't contain blue
^ # beginning of line
(?:(?!blue)[^\r\n])* # zero or more chars
# that do not start blue
(?:\r\n) # newline chars
)
Comment: With each line skipped, let Group 1 capture
Comment: an ever-growing portion of the string of numbers
Positive Lookahead (?= # lookahead
. # Go to the end of the file
( # start Group 1
~\d # match a tilde and digits
(?(1)\1) # if Group 1 is set, match Group 1
) # end Group 1
)
Assert that the Regex below matches
Comment: end lookahead
Comment: end counter-line-skipper: zero or more times
Comment: the possessive + forbids backtracking
Comment: lazily match any chars up to...
Comment: match blue
Comment: Get to the end of the data
Comment: match a tilde
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
Comment: drop what we matched so far
\d
matches a digit (equivalent to [0-9])Comment: match digits. This is the match!
Positive Lookahead (?=(?(1)\1))
Assert that the Regex below matches
Comment: if Group 1 has been set, match it