0

我正在提取以 Windows LogonIDs 结尾的事件......这意味着:

Special Privileges assigned to a new Logon: Logon Id: 0x007d

我认为这是最好的方法:

^(?<event>.+)(?<=ID:\s\d+x[A-F\d]+)$

使用RegexOptions.RightToLeft从字符串的末尾开始搜索。

使用lookbehind所以如果{ID: LogonId} 不存在,它将尽快失败。

由于我找不到任何好的从右到左测试仪,所以我在这里寻求您的帮助。

4

2 回答 2

1

我不明白您为什么需要 RightToLeft 选项后视。您是否使用这样的正则表达式对其进行了测试:

(?i)^(?<event>.+)ID:\s\d+x[A-F\d]+$

...发现它太慢了?

于 2011-05-24T21:20:30.907 回答
1

你能得到比赛的位置吗?在 Perl 中,可以这样做:

if ($str =~ /ID:\s\d+x[A-F\d]+$/i)
   say substr($str, 0, $-[0]);  # $-[0] is the starting pos of the match.
}

或者

if ($str =~ /ID:\s\d+x[A-F\d]+$/ip)
   say ${^PREMATCH};
}
于 2011-05-24T21:33:47.170 回答