Gregor1806 Posted June 16, 2016 Posted June 16, 2016 Hi, I'm trying to use regex to match some data inside the output from the command: reagentc.exe /info I want to determine whether Windows RE is enabled or not. I'm using 3 sample outputs from reagentc.exe /info that vary by OS (Win7 or Win8.1) and language (English or Japanese), and I'm trying to use regex to match regardless of the OS or language. Output from reagentc.exe /info on W7 in English is: Extended configuration for the Recovery Environment Windows RE enabled: 1 Windows RE staged: 1 Setup enabled: 1 Custom Recovery Tool: 1 WinRE.WIM directory: \\?\GLOBALROOT\device\harddisk0\partition3\Recovery\WindowsRE Recovery Environment: \\?\GLOBALROOT\device\harddisk0\partition3\Recovery\WindowsRE BCD Id: 33093dbe-2f2d-11e6-aa80-f46f281dee21 Setup Files: Recovery Operation: 4 Operation Parameter: Boot Key Scan Code 0x8500 REAGENTC.EXE: Operation successful Output from reagentc.exe /info on W7 in Japanese is: 恢复环境的扩展配置 已启用 Windows RE: 1 已暂存 Windows RE: 1 已启用安装程序: 1 自定义恢复工具: 1 WinRE.WIM 目录: \\?\GLOBALROOT\device\harddisk1\partition1\Recovery\WindowsRE 恢复环境: \\?\GLOBALROOT\device\harddisk1\partition1\Recovery\WindowsRE BCD Id: 5aae7821-32f3-11e6-b40e-64006a3a8e97 安装程序文件: 恢复操作: 4 操作参数: 启动密钥扫描代码 0x8500 REAGENTC.EXE: 操作成功 Output from reagentc.exe /info on W8.1 in English is: Windows Recovery Environment (Windows RE) and system reset configuration Information: Windows RE status: Enabled Windows RE location: \\?\GLOBALROOT\device\harddisk0\partition1\Recovery\WindowsRE Boot Configuration Data (BCD) identifier: 7e51fec8-a88c-11e3-b0a8-d4bed9846788 Recovery image location: \\?\GLOBALROOT\device\harddisk0\partition5\Dell\Image Recovery image index: 1 Custom image location: Custom image index: 0 I've been trying to use the http://regexr.com/ site to test various regex syntax and I've cobbled together the following pattern (which works OK on that website, but not in AutoIt): /(?=.*?\bWindows RE\b).*?\b:.*/g I tried using the pattern in AutoIt like this: $aREAgentCInfo = StringRegExp($sCMD, "(?=.*?\bWindows RE\b).*?\b.*", 3); Array of global matches (i.e. all matches in a multi-line string) If @error Then MsgBox(0, "", "Error: " & @error & @CRLF & "Extended: " & @extended) If IsArray($aREAgentCInfo) Then _ArrayDisplay($aREAgentCInfo, "Initial") $sCMD above is the output retrieved by running the reagentc.exe /info (with the outputs pasted earlier in this post). It just keeps returning with @Error set to 1 I have to admit, I don't understand regex and have tried to piece together the pattern from other regex example websites. Please can someone help me understand what I'm doing wrong? Thanks in advance G
mikell Posted June 16, 2016 Posted June 16, 2016 Please try this. If it works and if needed I'll give you the regex translation $test = StringRegExp($sCMD, '(?i)Windows RE\h*(?:enabled|status)?:\s*(?:1|enabled)') Msgbox(0,"", ($test = 1) ? "enabled" : "disabled")
Gregor1806 Posted June 16, 2016 Author Posted June 16, 2016 Hi mikell Yes, that works as I need, thanks so much! OK - please can you decode the regex for me now :-) Many thanks G
mikell Posted June 16, 2016 Posted June 16, 2016 OK, here it is StringRegExp used without parameter returns true or false, so this checks the presence of string(s) There is no capturing group needed, the whole expression must match to return true (?i)Windows RE\h*(?:enabled|status)?:\s*(?:1|enabled)') (?i) : case insensitiveWindows RE : checks "Windows RE"\h* : 0 or more horizontal white spaces(?:enabled|status)? : non-capturing group to check "enabled" OR "status". The "?" makes it optional (group may exist or not):\s* : a colon and 0 or more white spaces(?:1|enabled) : non-capturing group to check "1" OR "enabled", this also matches "Enabled" because of the (?i)
Gregor1806 Posted June 20, 2016 Author Posted June 20, 2016 Thanks for the explanation, very informative! G
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now