使用notepad ++删除仅包含电子邮件的所有联系人

时间:2016-01-27 14:12:23

标签: regex notepad++ vcard

在Notepad ++中,如何删除具有以下结构的所有条目。

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

注意:example@example.com可以是任何电子邮件地址。

我已经以vcf格式导出了整个联系人文件,并希望删除那些只有EMAIL地址而没有任何电话号码的人(如上所示)。

有没有办法在Notepad ++中执行此操作?也许通过使用正则表达式搜索和替换功能?

1 个答案:

答案 0 :(得分:2)

(?s)BEGIN:VCARD(?:(?!END:VCARD|\bTEL\b).)*END:VCARD
只有当vCards不包含TEL条目时,

才会匹配vCards。

<强>解释

(?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"

我假设所有的电子名片中都至少有一个电子邮件地址,或者您是否还需要过滤这些电子邮件地址?