Files
nix/tests
Eelco Dolstra 976df480c9 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
..
2014-02-26 18:59:01 +01:00
2014-08-21 21:50:19 +02:00
2013-10-17 11:18:37 +02:00
2014-07-11 16:22:24 +02:00
2014-08-21 21:50:19 +02:00
2014-09-23 15:18:44 +02:00
2014-08-21 21:50:19 +02:00
2014-08-21 21:50:19 +02:00
2014-02-26 18:00:46 +01:00
2006-07-21 13:21:43 +00:00
2014-05-02 19:02:10 +02:00
2014-08-21 21:50:19 +02:00
2014-08-28 18:23:55 +02:00
2014-08-21 21:50:19 +02:00
2014-08-21 21:50:19 +02:00
2014-02-01 15:37:50 +01:00
2012-09-12 11:29:10 -04:00
2014-02-26 17:53:51 +01:00
2014-02-06 13:54:44 +01:00
Doh
2014-02-26 22:41:29 +01:00
2007-08-13 13:15:02 +00:00
2014-08-20 18:03:48 +02:00
2012-12-04 14:47:50 +01:00
2012-12-04 14:47:50 +01:00
2014-08-21 21:50:19 +02:00