BlueBandana Posted October 2, 2019 Posted October 2, 2019 Is there a way to output the regex matches into a file? I have a script to compare two files and check for regex matches. I want to output the matching regex of 'testexample.txt' to another file. #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next
Nine Posted October 2, 2019 Posted October 2, 2019 If StringRegExp($regex, $pattern, 0) Then FileWriteLine ("Output.txt",$regex) EndIf This ? BlueBandana 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
seadoggie01 Posted October 2, 2019 Posted October 2, 2019 (edited) It sounds like you're looking for just the matching section to be written to the file, if so, check out the help page for StringRegExp and read up on the flag parameter. Edit: I would guess you're looking for Flag 3, but you can use this to check... I wrote this because I couldn't understand the what the flags did. Hope it helps #include <Array.au3> RegExpExample() Func RegExpExample() Local $sTest = '<test>a</test> <test>b</test> <test>c</Test>' Local $sPattern = '(?i)<test>(.*?)</test>' Local $vResult For $iFlag = 0 To 4 $vResult = StringRegExp($sTest, $sPattern, $iFlag) If @error Then ConsoleWrite("! StringRegExp Error: " & @error & @CRLF & @TAB & " Flag: " & $iFlag & @CRLF) ElseIf IsArray($vResult) Then If $iFlag = 4 Then For $i=0 To UBound($vResult) - 1 If IsArray($vResult[$i]) Then _ArrayDisplay($vResult[$i], "Flag " & $iFlag & " Part " & $i & "- StringRegExp Result") EndIf Next Else _ArrayDisplay($vResult, "Flag " & $iFlag & " - StringRegExp Result") EndIf Else MsgBox(0, "Flag " & $iFlag & " StringRegExp Result", $vResult) EndIf Next EndFunc Edited October 2, 2019 by seadoggie01 BlueBandana 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
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