vinnyMS Posted August 4, 2021 Share Posted August 4, 2021 i have a script that is supposed to extract text that includes or starts with the "@" character but it doesn't seem to work what is the problem with the regex? expandcollapse popup#include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> _Example() Func _Example() ; Error monitoring. This will trap all COM errors while alive. ; This particular object is declared as local, meaning after the function returns it will not exist. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $mypath = @ScriptDir Local $aFiles = _FileListToArrayRec($mypath, "*.txt", 1, 1) Local $aWords If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "No files found") Exit Else MsgBox($MB_SYSTEMMODAL, "Found", $aFiles[0] & " files") EndIf Local $aWords For $i = 1 To $aFiles[0] $aWords = StringRegExp(FileRead($aFiles[$i]), "(?mi)^\s*(@.*)$", 3) ; change pattern to fit your definition of "word Local $iError = @error If $iError = 0 Then For $Word In $aWords $oDictionary.add($Word, $Word) Next Else ;;MsgBox($MB_SYSTEMMODAL, "Error", $aFiles[$i] & " - " & $i & @CRLF & "error: " & $iError) EndIf Next $aWords = $oDictionary.Items FileWrite("New AutoIt v3 Script - acomercial.txt", _ArrayToString($aWords, @CRLF)) EndFunc ;==>_Example ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Link to comment Share on other sites More sharing options...
Nine Posted August 4, 2021 Share Posted August 4, 2021 (edited) Show examples of your files and expected results from SRE Edited August 4, 2021 by Nine “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) Screen Scraping Link to comment Share on other sites More sharing options...
vinnyMS Posted August 4, 2021 Author Share Posted August 4, 2021 1 hour ago, Nine said: Show examples of your files and expected results from SRE the source file is attached result: @NPC_RedPlayer @NPC_Main_0_0 @NPC_Main_0_1 @NPC_Main_0_2 @NPC_Main_0_3 @NPC_Main_0_4 @NPC_Buy @NPC_Sell @NPC_TQuest @NPC_TQuest_1 01Meet_Bichon1-0.txt result.txt Link to comment Share on other sites More sharing options...
Nine Posted August 5, 2021 Share Posted August 5, 2021 Maybe this : #include <Array.au3> Local $sText = FileRead("01Meet_Bichon1-0.txt") $aList = StringRegExp($sText, "(?m)^\[(@[^\]]*)", 3) _ArrayDisplay($aList) “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) Screen Scraping Link to comment Share on other sites More sharing options...
mikell Posted August 5, 2021 Share Posted August 5, 2021 (edited) Please be careful when defining the requirements This : 23 hours ago, vinnyMS said: extract text that includes or starts with the "@" character means that "@buy", "@sell", "@main" and "@exit" should match Edit BTW your regx didn't work because you omitted the brackets (as Nine pointed out) If you mention them, then miraculously it works : "(?mi)^\s*\[(@.*)\]$" Edited August 5, 2021 by mikell Link to comment Share on other sites More sharing options...
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