0

I read the manual on address autocompletion:

mu4e-compose-complete-ignore-address-regexp — a regular expression to filter out other ‘junk’ e-mail addresses; defaults to "no-?reply".

I am looking for a regular expression that matches that no-?reply username, a username and a domain, and a domain.

My first try was:

(setq mu4e-compose-complete-ignore-address-regexp
      (concat "\\(?:no-?reply"
          "\\|.*first\\.last@domain\\.com"
          "\\|.*@other-domain\\.com"
          "\\)"))

The middle match works and I am not prompted for that email address. The last match fails and I still have hundreds of completions for that domain name.

What is a regular expression that ignores those three types of addresses?

  • 1
    I suggest you use re-builder to build up your regexp and then use the result to set the mu4e variable. – NickD Feb 19 at 15:03
  • 2
    What is ?:no-?reply supposed to match? Why do you need the parens around the whole regexp? Instead of asking what's wrong, maybe you should describe what you are trying to match and ask what regex can match that. – NickD Feb 19 at 15:11
2

See here for explanations, but (forgetting about the tiresome escaping) the regex (?:...) is a shy group, i.e. a group that cannot be referred to through the \N mechanism. What you want is a straight alternation: match this OR that OR the other. The question mark in no-?reply has a different meaning: it matches zero or one of the previous char (or class or group), so no-?reply will match either noreply or no-reply. Putting it all together you end up with

no-?reply|first\.last@domain\.com|.*@other-domain\.com

and adding back the escapes:

(setq mu4e-compose-complete-ignore-address-regexp
      (concat "\\(no-?reply"
          "\\|first\\.last@domain\\.com"
          "\\|.*@other-domain\\.com"
          "\\)"))

should more-or-less work.

Caveats: It is not quite clear whether you need to group everything (i.e. whether the enclosing parens are necessary); it's also not clear that .* is correct for matching the user name in the other-domain.com case: it will match spaces, as well as alphanumerics and punctuation, so I don't think it conforms to email user-name syntax, but I'm not sure about the standard: you might want a character class like [a-zA-Z0-9.-] instead of the "anything goes" period, but take this with the appropriate grain of salt. Also, the * will allow matching the empty string which you probably want to avoid: use a + instead. I think I would prefer to write it like this:

(setq mu4e-compose-complete-ignore-address-regexp
      (concat "\\(no-?reply"
          "\\|first\\.last@domain\\.com"
          "\\|[a-zA-z0-9.-]+@other-domain\\.com"
          "\\)"))

Note that the period inside the character class [a-zA-z0-9.-] is a literal period and the - has to be at either the beginning or (as here) at the end, or else it is interpreted as a range (like a-z).

As mentioned in the comments, re-builder is an excellent way to interactively build and test a regex: you create a buffer, type a bunch of things that you want to match and a bunch of things that you don't want to match, then invoke re-builder and enter the proposed regex: it'll interactively show you what that regex matches and what it does not. It helps to have a basic idea of the regex you want, but you can take care of minor details this way.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.