困难的正则表达式,日期,PowerShell匹配

时间:2017-06-18 12:35:41

标签: regex powershell

想象一下,下面的日期/时间列表是此变量$OMSResult.LocalTime中的数组。

我试图选择星期六下午6点到11点59分之间的日期。我在PowerShell中使用正则表达式,但它不会返回任何答案。

这是我到目前为止所做的:

$OMSResult | ? ($_.LocalTime -match 'Saturday.+[6,11]:..:..\sPM')

以下是$OMSResult.LocalTime等同于的日期/值列表:

Sunday, June 18, 2017 12:01:25 AM
Saturday, June 17, 2017 11:58:40 PM
Saturday, June 17, 2017 11:57:29 PM
Saturday, June 17, 2017 11:56:27 PM
Saturday, June 17, 2017 11:56:27 PM
Saturday, June 17, 2017 11:53:12 PM
Saturday, June 17, 2017 11:52:09 PM
Saturday, June 17, 2017 11:51:05 PM
Saturday, June 17, 2017 11:48:55 PM
Saturday, June 17, 2017 11:45:42 PM
Saturday, June 17, 2017 11:44:36 PM
Saturday, June 17, 2017 11:44:36 PM
Saturday, June 17, 2017 11:43:30 PM
Saturday, June 17, 2017 11:43:30 PM
Saturday, June 17, 2017 11:41:19 PM
Saturday, June 17, 2017 11:40:13 PM
Saturday, June 17, 2017 11:39:10 PM
Saturday, June 17, 2017 11:36:45 PM
Saturday, June 17, 2017 11:35:41 PM
Saturday, June 17, 2017 11:32:22 PM
Saturday, June 17, 2017 11:32:22 PM
Saturday, June 17, 2017 11:32:22 PM
Saturday, June 17, 2017 11:28:55 PM
Saturday, June 17, 2017 11:28:55 PM
Saturday, June 17, 2017 11:27:48 PM
Saturday, June 17, 2017 11:26:47 PM
Saturday, June 17, 2017 11:26:47 PM
Saturday, June 17, 2017 11:25:39 PM
Saturday, June 17, 2017 11:24:36 PM
Saturday, June 17, 2017 11:24:36 PM
Saturday, June 17, 2017 11:19:14 PM
Saturday, June 17, 2017 11:18:12 PM
Saturday, June 17, 2017 11:18:12 PM
Saturday, June 17, 2017 11:18:12 PM
Saturday, June 17, 2017 11:17:04 PM
Saturday, June 17, 2017 11:14:53 PM
Saturday, June 17, 2017 11:14:53 PM
Saturday, June 17, 2017 11:13:50 PM
Saturday, June 17, 2017 11:12:41 PM
Saturday, June 17, 2017 11:11:36 PM
Saturday, June 17, 2017 11:11:36 PM
Saturday, June 17, 2017 11:10:25 PM
Saturday, June 17, 2017 11:09:18 PM
Saturday, June 17, 2017 11:08:12 PM
Saturday, June 17, 2017 11:08:12 PM
Saturday, June 17, 2017 11:06:07 PM
Saturday, June 17, 2017 11:03:54 PM
Saturday, June 17, 2017 10:59:36 PM
Saturday, June 17, 2017 10:57:30 PM
Saturday, June 17, 2017 10:55:23 PM
Saturday, June 17, 2017 10:55:23 PM
Saturday, June 17, 2017 10:53:09 PM
Saturday, June 17, 2017 10:52:04 PM
Saturday, June 17, 2017 10:49:57 PM
Saturday, June 17, 2017 10:48:54 PM
Saturday, June 17, 2017 10:48:54 PM
Saturday, June 17, 2017 10:47:38 PM
Saturday, June 17, 2017 10:46:33 PM
Saturday, June 17, 2017 10:44:23 PM
Saturday, June 17, 2017 10:43:22 PM
Saturday, June 17, 2017 10:43:22 PM
Saturday, June 17, 2017 10:42:17 PM
Saturday, June 17, 2017 10:40:09 PM
Saturday, June 17, 2017 10:37:56 PM
Saturday, June 17, 2017 10:37:56 PM
Saturday, June 17, 2017 10:32:38 PM
Saturday, June 17, 2017 10:29:23 PM
Saturday, June 17, 2017 10:29:23 PM
Saturday, June 17, 2017 10:26:02 PM
Saturday, June 17, 2017 10:26:02 PM
Saturday, June 17, 2017 10:23:59 PM
Saturday, June 17, 2017 10:22:47 PM
Saturday, June 17, 2017 10:21:43 PM
Saturday, June 17, 2017 10:20:38 PM
Saturday, June 17, 2017 10:18:22 PM
Saturday, June 17, 2017 10:16:17 PM
Saturday, June 17, 2017 10:16:17 PM
Saturday, June 17, 2017 10:16:17 PM
Saturday, June 17, 2017 10:15:07 PM
Saturday, June 17, 2017 10:13:59 PM
Saturday, June 17, 2017 10:11:45 PM
Saturday, June 17, 2017 10:11:45 PM
Saturday, June 17, 2017 10:11:45 PM
Saturday, June 17, 2017 10:09:39 PM
Saturday, June 17, 2017 10:08:33 PM
Saturday, June 17, 2017 10:07:26 PM
Saturday, June 17, 2017 10:04:09 PM
Saturday, June 17, 2017 10:04:09 PM
Saturday, June 17, 2017 10:03:02 PM
Saturday, June 17, 2017 10:01:57 PM
Saturday, June 17, 2017 10:00:50 PM
Saturday, June 17, 2017 9:59:46 PM
Saturday, June 17, 2017 9:57:34 PM
Saturday, June 17, 2017 9:56:31 PM
Saturday, June 17, 2017 9:55:27 PM
Saturday, June 17, 2017 9:53:14 PM
Saturday, June 17, 2017 9:52:12 PM
Saturday, June 17, 2017 9:49:02 PM
Saturday, June 17, 2017 9:47:55 PM
Saturday, June 17, 2017 9:44:46 PM
Saturday, June 17, 2017 9:44:46 PM
Saturday, June 17, 2017 9:42:29 PM
Saturday, June 17, 2017 9:41:27 PM
Saturday, June 17, 2017 9:41:27 PM
Saturday, June 17, 2017 9:39:14 PM
Saturday, June 17, 2017 9:37:04 PM
Saturday, June 17, 2017 9:34:55 PM
Saturday, June 17, 2017 9:34:55 PM
Saturday, June 17, 2017 9:32:48 PM
Saturday, June 17, 2017 9:31:48 PM
Saturday, June 17, 2017 9:29:37 PM
Saturday, June 17, 2017 9:29:37 PM
Saturday, June 17, 2017 9:29:37 PM
Saturday, June 17, 2017 9:28:32 PM
Saturday, June 17, 2017 9:28:32 PM
Saturday, June 17, 2017 9:26:22 PM
Saturday, June 17, 2017 9:25:18 PM
Saturday, June 17, 2017 9:23:03 PM
Saturday, June 17, 2017 9:23:03 PM
Saturday, June 17, 2017 9:21:59 PM
Saturday, June 17, 2017 9:18:50 PM
Saturday, June 17, 2017 9:17:41 PM
Saturday, June 17, 2017 9:17:41 PM
Saturday, June 17, 2017 9:15:33 PM
Saturday, June 17, 2017 9:13:24 PM
Saturday, June 17, 2017 9:12:17 PM
Saturday, June 17, 2017 9:12:17 PM
Saturday, June 17, 2017 9:12:17 PM
Saturday, June 17, 2017 9:11:12 PM
Saturday, June 17, 2017 9:09:07 PM
Saturday, June 17, 2017 9:08:02 PM
Saturday, June 17, 2017 9:05:54 PM
Saturday, June 17, 2017 9:04:48 PM
Saturday, June 17, 2017 9:03:40 PM
Saturday, June 17, 2017 9:00:21 PM
Saturday, June 17, 2017 9:00:21 PM
Saturday, June 17, 2017 8:59:18 PM
Saturday, June 17, 2017 8:57:09 PM
Saturday, June 17, 2017 8:56:03 PM
Saturday, June 17, 2017 8:52:45 PM
Saturday, June 17, 2017 8:51:42 PM
Saturday, June 17, 2017 8:49:34 PM
Saturday, June 17, 2017 8:48:33 PM
Saturday, June 17, 2017 8:47:29 PM
Saturday, June 17, 2017 8:47:29 PM
Saturday, June 17, 2017 8:45:19 PM
Saturday, June 17, 2017 8:44:18 PM
Saturday, June 17, 2017 8:44:18 PM
Saturday, June 17, 2017 8:43:13 PM
Saturday, June 17, 2017 8:40:07 PM
Saturday, June 17, 2017 8:39:00 PM
Saturday, June 17, 2017 8:39:00 PM
Saturday, June 17, 2017 8:36:50 PM
Saturday, June 17, 2017 8:36:50 PM
Saturday, June 17, 2017 8:34:42 PM
Saturday, June 17, 2017 8:33:38 PM
Saturday, June 17, 2017 8:32:36 PM
Saturday, June 17, 2017 8:30:30 PM
Saturday, June 17, 2017 8:29:26 PM
Saturday, June 17, 2017 8:28:17 PM
Saturday, June 17, 2017 8:27:14 PM
Saturday, June 17, 2017 8:27:14 PM
Saturday, June 17, 2017 8:26:12 PM
Saturday, June 17, 2017 8:23:59 PM
Saturday, June 17, 2017 8:22:51 PM
Saturday, June 17, 2017 8:21:46 PM
Saturday, June 17, 2017 8:19:40 PM
Saturday, June 17, 2017 8:18:40 PM
Saturday, June 17, 2017 8:18:40 PM
Saturday, June 17, 2017 8:16:28 PM
Saturday, June 17, 2017 8:15:28 PM
Saturday, June 17, 2017 8:15:28 PM
Saturday, June 17, 2017 8:13:13 PM
Saturday, June 17, 2017 8:12:09 PM
Saturday, June 17, 2017 8:12:09 PM
Saturday, June 17, 2017 8:11:00 PM
Saturday, June 17, 2017 8:09:43 PM
Saturday, June 17, 2017 8:09:43 PM
Saturday, June 17, 2017 8:09:43 PM
Saturday, June 17, 2017 8:07:28 PM
Saturday, June 17, 2017 8:06:20 PM
Saturday, June 17, 2017 8:06:20 PM
Saturday, June 17, 2017 8:05:17 PM
Saturday, June 17, 2017 8:02:06 PM
Saturday, June 17, 2017 8:01:04 PM
Saturday, June 17, 2017 7:58:56 PM
Saturday, June 17, 2017 7:57:48 PM
Saturday, June 17, 2017 7:55:39 PM
Saturday, June 17, 2017 7:54:37 PM
Saturday, June 17, 2017 7:54:37 PM
Saturday, June 17, 2017 7:54:37 PM
Saturday, June 17, 2017 7:53:26 PM
Saturday, June 17, 2017 7:52:24 PM
Saturday, June 17, 2017 7:51:20 PM
Saturday, June 17, 2017 7:51:20 PM
Saturday, June 17, 2017 7:50:15 PM
Saturday, June 17, 2017 7:49:07 PM
Saturday, June 17, 2017 7:47:57 PM
Saturday, June 17, 2017 7:46:55 PM
Saturday, June 17, 2017 7:46:55 PM
Saturday, June 17, 2017 7:45:48 PM
Saturday, June 17, 2017 7:44:43 PM
Saturday, June 17, 2017 7:43:38 PM
Saturday, June 17, 2017 7:43:38 PM
Saturday, June 17, 2017 7:42:28 PM
Saturday, June 17, 2017 7:42:28 PM
Saturday, June 17, 2017 7:40:16 PM
Saturday, June 17, 2017 7:40:16 PM
Saturday, June 17, 2017 7:39:10 PM
Saturday, June 17, 2017 7:39:10 PM
Saturday, June 17, 2017 7:38:00 PM
Saturday, June 17, 2017 7:35:51 PM
Saturday, June 17, 2017 7:34:50 PM
Saturday, June 17, 2017 7:34:50 PM
Saturday, June 17, 2017 7:31:35 PM
Saturday, June 17, 2017 7:30:30 PM
Saturday, June 17, 2017 7:30:30 PM
Saturday, June 17, 2017 7:30:30 PM
Saturday, June 17, 2017 7:28:23 PM
Saturday, June 17, 2017 7:27:17 PM
Saturday, June 17, 2017 7:27:17 PM
Saturday, June 17, 2017 7:27:17 PM
Saturday, June 17, 2017 7:25:13 PM
Saturday, June 17, 2017 7:24:11 PM
Saturday, June 17, 2017 7:24:11 PM
Saturday, June 17, 2017 7:23:06 PM
Saturday, June 17, 2017 7:21:58 PM
Saturday, June 17, 2017 7:21:58 PM
Saturday, June 17, 2017 7:20:56 PM
Saturday, June 17, 2017 7:20:56 PM
Saturday, June 17, 2017 7:19:56 PM
Saturday, June 17, 2017 7:18:54 PM
Saturday, June 17, 2017 7:18:54 PM
Saturday, June 17, 2017 7:17:40 PM
Saturday, June 17, 2017 7:16:38 PM
Saturday, June 17, 2017 7:14:29 PM
Saturday, June 17, 2017 7:14:29 PM
Saturday, June 17, 2017 7:14:29 PM
Saturday, June 17, 2017 7:13:22 PM
Saturday, June 17, 2017 7:13:22 PM
Saturday, June 17, 2017 7:12:14 PM
Saturday, June 17, 2017 7:12:14 PM
Saturday, June 17, 2017 7:12:14 PM
Saturday, June 17, 2017 7:11:05 PM
Saturday, June 17, 2017 7:11:05 PM
Saturday, June 17, 2017 7:10:03 PM
Saturday, June 17, 2017 7:10:03 PM
Saturday, June 17, 2017 7:08:57 PM
Saturday, June 17, 2017 7:07:52 PM
Saturday, June 17, 2017 7:07:52 PM
Saturday, June 17, 2017 7:06:46 PM
Saturday, June 17, 2017 7:05:42 PM
Saturday, June 17, 2017 7:04:38 PM
Saturday, June 17, 2017 7:03:34 PM
Saturday, June 17, 2017 7:03:34 PM
Saturday, June 17, 2017 7:02:29 PM
Saturday, June 17, 2017 7:01:21 PM
Saturday, June 17, 2017 7:00:21 PM
Saturday, June 17, 2017 7:00:21 PM
Saturday, June 17, 2017 6:59:20 PM
Saturday, June 17, 2017 6:57:14 PM
Saturday, June 17, 2017 6:57:14 PM
Saturday, June 17, 2017 6:57:14 PM
Saturday, June 17, 2017 6:56:08 PM
Saturday, June 17, 2017 6:54:02 PM
Saturday, June 17, 2017 6:54:02 PM
Saturday, June 17, 2017 6:54:02 PM
Saturday, June 17, 2017 6:50:54 PM
Saturday, June 17, 2017 6:50:54 PM
Saturday, June 17, 2017 6:50:54 PM
Saturday, June 17, 2017 6:49:53 PM
Saturday, June 17, 2017 6:48:52 PM
Saturday, June 17, 2017 6:47:43 PM
Saturday, June 17, 2017 6:46:40 PM
Saturday, June 17, 2017 6:45:36 PM
Saturday, June 17, 2017 6:45:36 PM
Saturday, June 17, 2017 6:44:30 PM
Saturday, June 17, 2017 6:43:23 PM
Saturday, June 17, 2017 6:42:16 PM
Saturday, June 17, 2017 6:42:16 PM
Saturday, June 17, 2017 6:40:05 PM
Saturday, June 17, 2017 6:38:56 PM
Saturday, June 17, 2017 6:37:48 PM
Saturday, June 17, 2017 6:35:41 PM
Saturday, June 17, 2017 6:35:41 PM
Saturday, June 17, 2017 6:35:41 PM
Saturday, June 17, 2017 6:32:31 PM
Saturday, June 17, 2017 6:31:26 PM
Saturday, June 17, 2017 6:29:19 PM
Saturday, June 17, 2017 6:28:11 PM
Saturday, June 17, 2017 6:28:11 PM
Saturday, June 17, 2017 6:28:11 PM
Saturday, June 17, 2017 6:25:04 PM
Saturday, June 17, 2017 6:25:04 PM
Saturday, June 17, 2017 6:25:04 PM
Saturday, June 17, 2017 6:25:04 PM
Saturday, June 17, 2017 6:21:49 PM
Saturday, June 17, 2017 6:21:49 PM
Saturday, June 17, 2017 6:21:49 PM
Saturday, June 17, 2017 6:20:47 PM
Saturday, June 17, 2017 6:19:39 PM
Saturday, June 17, 2017 6:19:39 PM
Saturday, June 17, 2017 6:17:33 PM
Saturday, June 17, 2017 6:16:24 PM
Saturday, June 17, 2017 6:15:21 PM
Saturday, June 17, 2017 6:15:21 PM
Saturday, June 17, 2017 6:14:14 PM
Saturday, June 17, 2017 6:14:14 PM
Saturday, June 17, 2017 6:13:05 PM
Saturday, June 17, 2017 6:13:05 PM
Saturday, June 17, 2017 6:11:54 PM
Saturday, June 17, 2017 6:11:54 PM
Saturday, June 17, 2017 6:10:50 PM
Saturday, June 17, 2017 6:10:50 PM
Saturday, June 17, 2017 6:08:39 PM
Saturday, June 17, 2017 6:07:38 PM
Saturday, June 17, 2017 6:07:38 PM
Saturday, June 17, 2017 6:07:38 PM
Saturday, June 17, 2017 6:05:24 PM
Saturday, June 17, 2017 6:04:20 PM
Saturday, June 17, 2017 6:03:08 PM
Saturday, June 17, 2017 5:59:57 PM
Saturday, June 17, 2017 5:58:55 PM
Saturday, June 17, 2017 5:58:55 PM
Saturday, June 17, 2017 5:55:39 PM
Saturday, June 17, 2017 5:55:39 PM
Saturday, June 17, 2017 5:55:39 PM
Saturday, June 17, 2017 5:55:39 PM
Saturday, June 17, 2017 5:55:39 PM
Saturday, June 17, 2017 5:55:39 PM
Saturday, June 17, 2017 5:54:26 PM
Saturday, June 17, 2017 5:54:26 PM
Saturday, June 17, 2017 5:53:20 PM
Saturday, June 17, 2017 5:53:20 PM
Saturday, June 17, 2017 5:52:12 PM
Saturday, June 17, 2017 5:52:12 PM
Saturday, June 17, 2017 5:51:05 PM
Saturday, June 17, 2017 5:51:05 PM
Saturday, June 17, 2017 5:51:05 PM
Saturday, June 17, 2017 5:51:05 PM
Saturday, June 17, 2017 5:49:59 PM
Saturday, June 17, 2017 5:48:53 PM
Saturday, June 17, 2017 5:48:53 PM
Saturday, June 17, 2017 5:48:53 PM
Saturday, June 17, 2017 5:47:51 PM
Saturday, June 17, 2017 5:46:53 PM
Saturday, June 17, 2017 5:46:53 PM
Saturday, June 17, 2017 5:45:48 PM
Saturday, June 17, 2017 5:45:48 PM
Saturday, June 17, 2017 5:44:43 PM
Saturday, June 17, 2017 5:43:43 PM
Saturday, June 17, 2017 5:40:32 PM
Saturday, June 17, 2017 5:40:32 PM
Saturday, June 17, 2017 5:40:32 PM
Saturday, June 17, 2017 5:40:32 PM
Saturday, June 17, 2017 5:40:32 PM
Saturday, June 17, 2017 5:39:30 PM
Saturday, June 17, 2017 5:39:30 PM
Saturday, June 17, 2017 5:38:26 PM

1 个答案:

答案 0 :(得分:2)

这里使用正则表达式是个坏主意,因为你已经有了DateTime个对象的列表?如果您只能使用对象在过滤表达式中提供的属性,为什么要进行文本匹配?

这应该可以解决问题:

$OMSResult | ?{ $_.ToLocalTime().DayOfWeek -eq [DayOfWeek]::Saturday -and $_.ToLocalTime().TimeOfDay -ge [TimeSpan]'18:00:00' }