forked from lix-project/lix
976df480c9
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 ./.) |
||
---|---|---|
.. | ||
attr-path.cc | ||
attr-path.hh | ||
common-opts.cc | ||
common-opts.hh | ||
eval-inline.hh | ||
eval.cc | ||
eval.hh | ||
get-drvs.cc | ||
get-drvs.hh | ||
json-to-value.cc | ||
json-to-value.hh | ||
lexer.l | ||
local.mk | ||
names.cc | ||
names.hh | ||
nix-expr.pc.in | ||
nixexpr.cc | ||
nixexpr.hh | ||
parser.y | ||
primops.cc | ||
symbol-table.hh | ||
value-to-json.cc | ||
value-to-json.hh | ||
value-to-xml.cc | ||
value-to-xml.hh | ||
value.hh |