Files
nix/tests/lang
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-10-03 22:32:11 +02:00
2006-03-01 16:26:13 +00:00
2014-09-22 16:05:00 +02:00
2006-05-02 11:20:55 +00:00
2014-09-22 16:05:00 +02:00
2007-01-29 14:23:09 +00:00
2006-10-17 11:16:02 +00:00
2011-07-06 10:58:53 +00:00
2011-07-06 10:58:53 +00:00
2006-03-01 16:26:13 +00:00
2014-09-22 16:05:00 +02:00
2014-09-22 16:05:00 +02:00
2013-12-31 20:59:49 +00:00
2013-12-31 20:59:49 +00:00
2014-02-26 19:08:44 +01:00
2014-02-26 19:08:44 +01:00
2014-02-26 19:08:44 +01:00
2014-02-26 19:08:44 +01:00
2006-03-01 16:26:13 +00:00
2008-02-05 13:25:18 +00:00
2004-10-27 12:41:53 +00:00
2006-03-01 16:26:13 +00:00
2006-05-02 11:15:04 +00:00
2006-05-02 11:20:55 +00:00
2014-05-29 19:04:27 +02:00
2014-09-22 16:05:00 +02:00
2014-09-22 16:05:00 +02:00
2013-11-19 00:04:11 +01:00
2013-11-19 00:04:11 +01:00
2010-05-07 14:46:47 +00:00
2010-05-07 14:46:47 +00:00
2010-05-07 14:46:47 +00:00
2014-02-26 19:08:44 +01:00
2014-02-26 19:08:44 +01:00
2010-03-23 14:51:32 +00:00
2014-05-26 14:26:29 +02:00
2014-05-26 14:26:29 +02:00
2014-02-26 19:08:44 +01:00
2004-10-27 12:41:53 +00:00
2006-08-16 10:29:43 +00:00
2004-10-27 12:41:53 +00:00