aboutsummaryrefslogtreecommitdiff
path: root/tests/lang/eval-okay-regex-match.exp
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-25 11:47:06 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-25 11:47:06 +0100
commit976df480c918f050608f7a23a4a21415c43475c3 (patch)
tree41463834cb5e30bd50c719f6ccaa8ecdb3a8a976 /tests/lang/eval-okay-regex-match.exp
parent4e340a983f928973d3915455d46a4bbadbc3269c (diff)
Add a primop for regular expression pattern matching
The function ‘builtins.match’ takes a POSIX extended regular expression and an arbitrary string. It returns ‘null’ if the string does not match the regular expression. Otherwise, it returns a list containing substring matches corresponding to parenthesis groups in the regex. The regex must match the entire string (i.e. there is an implied "^<pat>$" around the regex). For example: match "foo" "foobar" => null match "foo" "foo" => [] match "f(o+)(.*)" "foooobar" => ["oooo" "bar"] match "(.*/)?([^/]*)" "/dir/file.nix" => ["/dir/" "file.nix"] match "(.*/)?([^/]*)" "file.nix" => [null "file.nix"] The following example finds all regular files with extension .nix or .patch underneath the current directory: let findFiles = pat: dir: concatLists (mapAttrsToList (name: type: if type == "directory" then findFiles pat (dir + "/" + name) else if type == "regular" && match pat name != null then [(dir + "/" + name)] else []) (readDir dir)); in findFiles ".*\\.(nix|patch)" (toString ./.)
Diffstat (limited to 'tests/lang/eval-okay-regex-match.exp')
-rw-r--r--tests/lang/eval-okay-regex-match.exp1
1 files changed, 1 insertions, 0 deletions
diff --git a/tests/lang/eval-okay-regex-match.exp b/tests/lang/eval-okay-regex-match.exp
new file mode 100644
index 000000000..27ba77dda
--- /dev/null
+++ b/tests/lang/eval-okay-regex-match.exp
@@ -0,0 +1 @@
+true