aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-12-26 16:55:32 -0500
committerSean Allred <code@seanallred.com>2014-12-26 16:55:32 -0500
commit0e54ca6ad3e4cf11b5512fadef39066e955e6281 (patch)
tree5408dca5c1a6ef5634f1007a7bf1cf38cee74cb2
parent31a3e357261641228186692ab3a9ac0a053d197b (diff)
Use `rx' macro for some regular expressions
-rw-r--r--sx.el25
1 files changed, 21 insertions, 4 deletions
diff --git a/sx.el b/sx.el
index 8913024..091526f 100644
--- a/sx.el
+++ b/sx.el
@@ -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))