diff options
author | Sean Allred <code@seanallred.com> | 2014-12-26 16:55:32 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-12-26 16:55:32 -0500 |
commit | 0e54ca6ad3e4cf11b5512fadef39066e955e6281 (patch) | |
tree | 5408dca5c1a6ef5634f1007a7bf1cf38cee74cb2 | |
parent | 31a3e357261641228186692ab3a9ac0a053d197b (diff) |
Use `rx' macro for some regular expressions
-rw-r--r-- | sx.el | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -322,12 +322,29 @@ If ALIST doesn't have a `site' property, one is created using the (let ((result (list (cons 'site (sx--site link))))) (when (or ;; Answer - (and (or (string-match "/a/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) - (string-match "/questions/[0-9]+/[^/]+/\\([0-9]\\)/?\\(#.*\\|\\)\\'" link)) + (and (or (string-match + (rx "/a/" (group (1+ digit)) "/" + (1+ digit) + (group (or (sequence "#" (0+ any)) "")) + string-end) link) + (string-match + (rx "/questions/" (1+ digit) "/" + (1+ (not (any "/"))) "/" + (group digit) + (optional "/") + (group (or (sequence "#" (0+ any)) "")) + string-end) link)) (push '(type . answer) result)) ;; Question - (and (or (string-match "/q/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) - (string-match "/questions/\\([0-9]+\\)/" link)) + (and (or (string-match + (rx "/q/" + (group (1+ digit)) "/" + (1+ digit) + (group (or (sequence "#" (0+ any)) "")) + string-end) link) + (string-match + (rx "/questions/" + (group (1+ digit)) "/") link)) (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) result)) |