我正在尝试根据一些 XML 文件的单词列表进行一些模式匹配。
我有以下内容:
$Result = Get-ChildItem -Recurse $FullPath\*.xml |
Select-String -Pattern $WordList |
Select-Object Path, Pattern, Line, LineNumber
我的问题出现在同一行代码中有多个匹配项时,
例如,如果 $WordList = "AA","AACC",则该行是:
"This is a test line AA, BB, AACC, KK"
$Result 将只是基于第一个单词 (AA) 的单行匹配。但它不会给我所有三个结果,一个是基于“AA”的两个匹配,另一个是基于“AACC”的匹配,都在同一行。
当前 $Result:
Path Pattern Line LineNumber
** AA This is a test line AA, BB, AACC, KK 12
理想的 $Result:
Path Pattern Line LineNumber
** AA This is a test line AA, BB, AACC, KK 12
** AA This is a test line AA, BB, AACC, KK 12
** AACC This is a test line AA, AABB, AACC, KK 12