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
..
2011-08-06 16:05:24 +00:00
2011-08-06 16:05:24 +00:00
2011-08-06 16:05:24 +00:00
2011-08-06 16:05:24 +00:00
2014-10-03 22:32:11 +02:00
2006-08-23 15:46:00 +00:00
2013-10-16 23:29:11 +02:00
2006-03-01 16:26:13 +00:00
2013-10-17 00:51:07 +02:00
2013-10-17 00:51:07 +02:00
2013-10-17 00:51:07 +02:00
2004-10-27 12:41:53 +00:00
2014-09-22 16:05:00 +02:00
2006-05-08 12:52:47 +00:00
2005-05-18 17:19:21 +00: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
2006-05-08 12:52:47 +00:00
2013-08-02 18:53:02 +02:00
2014-02-26 19:08:44 +01:00
2010-04-21 16:22:03 +00:00
2014-10-04 16:41:24 +02:00
2010-04-21 16:22:03 +00:00
2006-09-22 14:31:55 +00:00
2010-04-21 16:22:03 +00:00
2009-05-15 12:35:23 +00:00
2011-07-06 10:58:53 +00:00
2011-07-06 10:58:53 +00:00
2011-07-13 12:19:57 +00:00
2012-09-27 15:49:20 -04:00
2010-04-21 16:22:03 +00:00
2006-03-01 16:26:13 +00:00
2010-04-21 16:22:03 +00:00
2007-01-14 12:32:44 +00:00
2013-08-26 11:15:22 +02:00
2010-04-21 16:22:03 +00:00
2006-08-23 14:39:11 +00:00
2014-11-15 16:12:05 -05:00
2014-11-15 16:12:05 -05:00
2014-10-04 18:15:03 +02:00
2014-10-04 18:15:03 +02:00
2008-07-11 13:29:04 +00:00
2008-07-11 13:29:04 +00:00
2010-04-21 16:22:03 +00:00
2005-07-25 15:05:34 +00:00
2010-04-22 11:02:24 +00:00
2014-06-10 14:02:56 +02:00
2013-11-18 20:16:02 +01:00
2013-11-18 20:16:02 +01:00
2014-09-22 16:05:00 +02:00
2014-09-22 16:05:00 +02:00
2013-08-26 11:31:56 +02:00
2013-08-26 11:31:56 +02:00
2013-07-31 13:12:35 +02:00
2013-07-31 13:12:35 +02:00
2013-12-31 17:57:10 -05:00
2013-12-31 17:57:10 -05:00
2014-01-14 14:00:15 +01:00
2014-01-14 14:00:15 +01: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
2010-04-21 16:22:03 +00:00
2007-05-15 12:14:37 +00:00
2012-01-19 22:10:24 +00:00
2012-01-19 22:10:24 +00:00
2006-08-30 13:10:04 +00:00
2006-08-30 12:25:27 +00:00
2014-02-26 19:08:44 +01:00
2014-02-26 19:08:44 +01:00
2010-04-21 16:22:03 +00:00
2006-09-22 15:29:21 +00:00
2014-07-04 13:34:15 +02:00
2014-07-04 13:34:15 +02:00
2009-09-15 13:01:46 +00:00
2009-09-15 13:01:46 +00:00
2013-11-18 22:22:35 +01:00
2013-11-18 22:22:35 +01:00
2010-04-21 16:22:03 +00:00
2006-09-24 17:48:41 +00:00
2013-02-08 19:36:23 +01:00
2013-02-08 19:36:23 +01:00
2010-04-21 16:22:03 +00:00
2006-03-01 16:26:13 +00:00
2014-05-26 14:26:29 +02:00
2014-05-26 14:26:29 +02:00
2010-04-21 16:22:03 +00:00
2008-02-05 13:25:18 +00:00
2010-04-21 16:22:03 +00:00
2004-10-27 12:41:53 +00:00
2010-04-21 16:22:03 +00:00
2006-09-22 15:29:21 +00:00
2010-10-23 22:55:30 +00:00
2010-10-24 19:52:33 +00:00
2010-04-21 16:22:03 +00:00
2006-03-01 16:26:13 +00:00
2010-04-21 16:22:03 +00:00
2006-09-22 15:29:21 +00:00
2010-04-21 16:22:03 +00:00
2006-10-02 15:52:44 +00:00
2014-03-10 10:14:50 +01:00
2014-03-10 10:14:50 +01:00
2010-10-22 15:15:12 +00:00
2010-10-22 15:15:12 +00:00
2010-04-21 16:22:03 +00:00
2006-10-17 11:08:59 +00:00
2010-04-21 16:22:03 +00:00
2010-03-25 12:19:41 +00:00
2014-10-03 22:32:11 +02:00
2014-10-03 22:32:11 +02:00
2010-04-21 16:22:03 +00:00
2007-11-21 13:49:59 +00:00
2013-12-31 17:45:47 +00:00
2013-12-31 17:45:47 +00:00
2014-11-25 11:47:06 +01:00
2014-11-25 11:47:06 +01:00
2010-04-21 16:22:03 +00:00
2005-05-18 17:19:21 +00:00
2010-04-21 16:22:03 +00:00
2004-10-27 12:41:53 +00:00
2010-04-21 16:22:03 +00:00
2004-10-27 12:41:53 +00:00
2010-04-21 16:22:03 +00:00
2004-10-27 12:41:53 +00:00
2010-04-21 16:22:03 +00:00
2006-05-02 11:15:04 +00:00
2010-04-21 16:22:03 +00:00
2006-05-02 11:20:55 +00:00
2010-04-21 16:22:03 +00:00
2009-05-15 13:46:13 +00:00
2014-05-29 19:04:27 +02:00
2011-08-06 17:48:57 +00:00
2014-07-30 11:28:39 +02:00
2014-09-22 16:05:00 +02:00
2014-09-22 16:05:00 +02:00
2010-04-21 16:22:03 +00:00
2006-10-17 11:08:59 +00:00
2011-07-13 15:53:24 +00:00
2011-07-13 15:53:24 +00:00
2011-01-14 12:47:10 +00:00
2011-01-14 12:47:10 +00:00
2014-01-06 11:32:22 +01:00
2013-11-12 12:34:22 +01: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
2010-03-31 12:38:31 +00:00
2010-05-12 12:15:49 +00:00
2010-05-12 11:23:44 +00:00
2014-02-26 19:08:44 +01:00
2014-02-26 19:08:44 +01:00
2010-04-21 16:22:03 +00:00
2008-07-01 10:10:32 +00:00
2010-04-21 16:22:03 +00:00
2010-03-23 14:51:32 +00:00
2010-03-25 12:19:41 +00:00
2008-08-14 14:00:44 +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
2005-03-10 11:33:46 +00:00
2005-03-10 11:33:46 +00:00
2005-03-10 11:33:46 +00:00
2009-05-15 12:35:23 +00:00
2009-05-15 12:35:23 +00:00
2010-04-22 11:02:24 +00:00
2005-03-10 11:33:46 +00:00
2008-08-14 12:53:29 +00:00
2006-07-10 17:35:00 +00:00
2006-07-24 16:35:34 +00:00
2005-03-10 11:33:46 +00:00
2004-10-27 12:41:53 +00:00
2006-08-16 10:29:43 +00:00
2010-04-22 11:02:24 +00:00
2004-10-27 13:00:31 +00:00
2004-10-27 13:12:58 +00:00
2004-10-27 12:41:53 +00:00