summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authorKyle Hargraves <pd@krh.me>2012-12-17 15:23:21 -0600
committerKyle Hargraves <pd@krh.me>2012-12-17 15:23:21 -0600
commit01e884d22a4395c1175d61d8b8c2fdcb982d3443 (patch)
treeeded26f83988eae666c4f6ebe65001e932e2f426 /dev
parent8ff6245fadf58a11bc5e2104601bc5856106d2e0 (diff)
s-match: support optional capture groups
The values of match-data do not seem to support the ideal case. For the test of "(abc)(def)?" matching against "abc", the most reasonable result would be ("abc" "abc" nil); however, match-data provides no indication of the second capture group. Without this, though, s-match errors when match-data contains nils.
Diffstat (limited to 'dev')
-rw-r--r--dev/examples.el5
1 files changed, 4 insertions, 1 deletions
diff --git a/dev/examples.el b/dev/examples.el
index bc23eee..ffebcef 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -111,7 +111,10 @@
(s-match "^def" "abcdefg") => nil
(s-match "^abc" "abcdefg") => '("abc")
(s-match "^/.*/\\([a-z]+\\)\\.\\([a-z]+\\)" "/some/weird/file.html") => '("/some/weird/file.html" "file" "html")
- (s-match "^/.*/\\([a-z]+\\)\\.\\([a-z]+\\)" "/some/weird/file.org") => '("/some/weird/file.org" "file" "org"))
+ (s-match "^/.*/\\([a-z]+\\)\\.\\([a-z]+\\)" "/some/weird/file.org") => '("/some/weird/file.org" "file" "org")
+ (s-match "^\\(abc\\)\\(def\\)?" "abcdef") => '("abcdef" "abc" "def")
+ (s-match "^\\(abc\\)\\(def\\)?" "abc") => '("abc" "abc")
+ (s-match "^\\(abc\\)\\(def\\)?\\(ghi\\)" "abcghi") => '("abcghi" "abc" nil "ghi"))
(defexamples s-join
(s-join "+" '("abc" "def" "ghi")) => "abc+def+ghi"