【发布时间】:2019-11-11 06:30:24
【问题描述】:
我有一个列表,其中包含一些字符串和其他数据。
HwndWrapper[App.exe;;cda6c3f4-8c87-4b12-8f3d-5322ca90eeex]
HwndWrapper[App.exe;;cadac3f4-8c87-4b12-8q3d-1qwe2ca90eec]
HwndWrapper[App.exe;;c1b6a3s4-8c87-4b12-8f3d-2qw2ca90eeev]
我的清单: // 返回 WindowInformation 对象的列表,其中包含 Handle、Caption、Class、 // 父、子、兄弟和进程信息
List<WindowInformation> windowListExtended = WindowList.GetAllWindowsExtendedInfo();
要匹配的正则表达式是:
HwndWrapper\[App.exe;;.*?\]
现在对于列表中的每场比赛。我需要提取匹配的字符串并使用提取的每个字符串运行一个进程,Foreach 或类似的东西。
请帮忙。
更新: 感谢 Altaris 的帮助,只需要将 List 转换为字符串
var message = string.Join(",", windowListExtended);
string pattern = @"HwndWrapper\[LogiOverlay.exe;;.*?]";
MatchCollection matches = Regex.Matches(message, pattern);
【问题讨论】:
-
你的正则表达式应该是这样的: HwndWrapper[App\.exe;;(.*?)] 然后提取的字符串可以被 Group 1 检索
-
我找不到太多关于 WindowInformation 对象以及如何使用它的信息,也许这可以帮助你stackoverflow.com/questions/7268302/…
-
窗口是非活动的,非标准窗口,没有名称,只有类以相对简单的方式可用。 ;(感谢您的帮助。
-
我还是不明白你从哪里得到这个字符串 "HwndWrapper[App.exe;;cda6c3f4-8c87-4b12-8f3d-5322ca90eeex]"
-
我从所有窗口列表中提取。无论如何,您的解决方案就像一个魅力,非常简单,只需转换为字符串 var message = string.Join(",", windowListExtended);字符串模式 = @"HwndWrapper[LogiOverlay.exe;;.*?]"; MatchCollection 匹配 = Regex.Matches(message, pattern);非常感谢您的帮助!