Delete all content but keeping matched

Solution 1:

You may use the following regex:

(?i-s)[0-9]([a-z])|.

Replace with (?{1}$1:).

To delete all but non-matched, use the (?{1}$0:) replacement with the same regex.

Details:

  • (?i-s) - an inline modifier turning on case insensitive mode and turning off the DOTALL mode (. does not match a newline)
  • [0-9]([a-z]) - an ASCII digit and any ASCII letter captured into Group 1 (later referred to with $1 or \1 backreference from the string replacement pattern)
  • | - or
  • . - any char but a line break char.

Replacement details

  • (?{1} - start of the conditional replacement: if Group 1 matched then...
    • $1 - the contents of Group 1 (or the whole match if $0 backreference is used)
    • : - else... nothing
  • ) - end of the conditional replacement pattern.

enter image description here