Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex powershell中的正则表达式前瞻行为异常_Regex_String_Powershell_Logging - Fatal编程技术网

Regex powershell中的正则表达式前瞻行为异常

Regex powershell中的正则表达式前瞻行为异常,regex,string,powershell,logging,Regex,String,Powershell,Logging,我会第一个承认我不是最好的正则表达式作者。我正在尝试分析powershell中的日志文件。日志文件以日期时间戳开始,可以是多行的。例如: 2017-01-10T17:52:24.224-05:00 DEBUG (0EC3-018C) < ThisIsAClassName> [blah] log lines are here this is an addition to the previous line So is this at 2017-01 201

我会第一个承认我不是最好的正则表达式作者。我正在尝试分析powershell中的日志文件。日志文件以日期时间戳开始,可以是多行的。例如:

2017-01-10T17:52:24.224-05:00 DEBUG (0EC3-018C) < ThisIsAClassName> [blah] log lines are here
     this is an addition to the previous line
     So is this at 2017-01     
2017-01-10T17:52:26.224-05:00 DEBUG (0EC3-018C) < ThisIsADiffClassName> [blah] log lines are here

这正好给了我输入。为了按时间戳分割行,我做错了什么

我知道您处理的是多行内容。在这种情况下,拆分要比匹配容易得多:

或者,为了避免开始时出现空元素,添加\^之前或之后的前瞻:


这将类似于?m^?=\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}最后,并将匹配任何行的起始位置?m multiline修饰符将使“^匹配行的起始位置”,而不是跟随时间戳模式的整个字符串,但时间戳文本不会被使用=不会成为匹配值的一部分,因此将出现在拆分文本中,因为它在?=。。。正向前瞻结构

你一定要配吗?您可以使用?m^?=+Timestamp+[.|\w]进行拆分。它看起来不正确,它与任何内容都不匹配,它只匹配单词字符、文字点符号、文字管道符号。并且只出现一次。@WiktorStribiżew效果很好!你愿意把它作为一个答案,这样我就可以接受并给你信用吗?
Timestamp         = "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}"
Anything          = "[.|\w]"
NegativeLookahead = "(?!(" + Timestamp + "))"
FullRegex         = Timestamp + Anything + NegativeLookahead
"(?m)^(?=" + Timestamp + ")"
"(?m)(?!\A)^(?=" + Timestamp + ")"