-1

In Notepad++, how can I remove all entries that have the following structure.

BEGIN:VCARD
VERSION:2.1
EMAIL;INTERNET:example@example.com
END:VCARD

Note: that example@example.com could be any email address.

I've exported a whole file of contacts in vcf format, and would like to remove the ones that have only EMAIL addresses without any phone number (like seen above).

Is there a way to do this in Notepad++? Maybe by using the Regex Search and Replace feature?

Norman
  • 6,159
  • 23
  • 88
  • 141

1 Answers1

2
(?s)BEGIN:VCARD(?:(?!END:VCARD|\bTEL\b).)*END:VCARD

will match vCards only if they don't contain a TEL entry.

Explanation:

(?s)          # Allow the dot to match newlines.
BEGIN:VCARD   # Match "BEGIN:VCARD".
(?:           # Start non-capturing group.
 (?!          # Make sure we're not able to match either
  END:VCARD   # the text "END:VCARD" (we don't want to match beyond the end)
 |            # or
  \bTEL\b     # "TEL" (because we don't want them to be in the match).
 )            # End of lookahead.
 .            # Match any character (if the preceding condition is fulfilled),
)*            # repeat as needed.
END:VCARD     # Match "END:VCARD"

I'm assuming that all the vCards have at least an email address in them, or do you also need to filter for those?

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561