Regex to match unescaped characters only
Problem: Find key-value pairs separated by : but ignore escaped colons, i.e. \:. Solution: Negative lookbehinds – see Regex Tutorial – Lookaheads and Lookbehinds. “Positive” means “must match”, “Negative” means “must not match”. Over here, we are “looking behind” the backslash to ensure that a colon is not matched. Single match in a string: <?php …