[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cleaning up a big regexp
From: |
Thorsten Jolitz |
Subject: |
Re: cleaning up a big regexp |
Date: |
Mon, 15 Sep 2014 16:35:15 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
torys.anderson@gmail.com (Tory S. Anderson) writes:
> Using gnus I have a growing regexp that represents the criteria for bulk
> email and splits accordingly:
>
> (setq my-gnus-bulk-regexp )
>
> ;; TODO make bulk-list
> (setq nnmail-split-methods
> '(("mail.bulk" my-gnus-bulk-regexp)
> ...
>
>
> Is there a way to clean this up to make it both more readable and more
> easily editable? It seems like keeping some kind of list would be the
> way to do it, instead of an ever-lengthening string.
I have a little library called drx.el on github
(https://github.com/tj64/drx ) which isn't as extreme as rx.el in
avoiding regexp strings, but is pretty flexible when it comes to avoid
all the plumbing/glue-code between the actual regexp strings.
Furthermore it abstracts from 3 common regexp elements: "^", "$" and
"\\*", so it lets you e.g. write a regexp for Org-mode:
#+BEGIN_SRC emacs-lisp :results raw
(require 'drx)
(format "%S"
(drx "foo" t '(t nil (2)) t '(nil t (2))
"bar" "loo"))
#+END_SRC
#+results:
"^\\(\\*\\(\\*\\)\\{2\\}\\)foo\\(bar\\)\\(loo\\)\\{2\\}$"
and reuse it for css mode with different outline stars:
#+BEGIN_SRC emacs-lisp :results raw
(require 'drx)
(let ((drx-BOL "^/\\* ")
(drx-EOL " \\*/$")
(drx-STAR "@"))
(format "%S"
(drx "foo" t '(t nil (2)) t '(nil t (2))
"bar" "loo")))
#+END_SRC
#+results:
"^/\\* \\(@\\(@\\)\\{2\\}\\)foo\\(bar\\)\\(loo\\)\\{2\\} \\*/$"
Here is something similar to your example regexp:
#+BEGIN_SRC emacs-lisp :results raw
(require 'drx)
(format "%S"
(drx
(drx "From:.*" t nil nil 'group
(drx "@maillist.codeproject.com" nil nil nil 'alt
"@papajohns-specials.com"
"@qomail.quikorder.com"
"@linkedin.com"
"@facebookmail.com"
"@plus.google.com"
"@twitter.com"
"@youtube.com"
"@linguistlist.org"
"sportsauthority.com"))
nil nil nil 'alt
(drx "To:.*torysanderson@gmail.com" nil nil nil t)))
#+END_SRC
#+results:
"\\(^\\(From:.*\\(@maillist.codeproject.com\\|@papajohns-specials.com\\|@qomail.quikorder.com\\|@linkedin.com\\|@facebookmail.com\\|@plus.google.com\\|@twitter.com\\|@youtube.com\\|@linguistlist.org\\|sportsauthority.com\\)\\)\\|\\(To:.*torysanderson@gmail.com\\)\\)"
--
cheers,
Thorsten
- cleaning up a big regexp, Tory S. Anderson, 2014/09/15
- Re: cleaning up a big regexp, Joost Kremers, 2014/09/15
- Re: cleaning up a big regexp, Tory S. Anderson, 2014/09/15
- Re: cleaning up a big regexp, Michael Albinus, 2014/09/15
- Re: cleaning up a big regexp, Tory S. Anderson, 2014/09/15
- Re: cleaning up a big regexp, Michael Albinus, 2014/09/15
- Re: cleaning up a big regexp, Stefan Monnier, 2014/09/15
- Re: cleaning up a big regexp, Michael Albinus, 2014/09/15
- Thanks! Re: cleaning up a big regexp, Tory S. Anderson, 2014/09/15
- Re: cleaning up a big regexp, Stefan Monnier, 2014/09/15
- Regexp in nnmail-split-methods (was Re: cleaning up a big regexp), Tory S. Anderson, 2014/09/16