This website requires JavaScript.
Explore
Help
Register
Sign in
mdebray
/
tvl-depot
Watch
1
Star
0
Fork
You've already forked tvl-depot
0
Code
Issues
Pull requests
Projects
Releases
Packages
Wiki
Activity
Actions
2e8fd4c5cd
tvl-depot
/
tests
/
lang
/
eval-okay-regex-match.exp
2 lines
5 B
Text
Raw
Normal View
History
Unescape
Escape
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 ./.)
2014-11-25 11:47:06 +01:00
true
Reference in a new issue
Copy permalink