
DCCD
-
Posts
310 -
Joined
-
Last visited
Reputation Activity
-
DCCD got a reaction from AndrewSchultz in Match start/end of string!
How to? Search for a string starting with "UBX" or "FLN" ends with @yahoo.com
what am I missing here?
;#include <Constants.au3> ;#include <Pacap.au3> ;#include <plug.au3> $handle__ = FileOpenDialog('OpenScure', @WorkingDir & "\", "Pcap (*.cap;*.pcap;*.log)") $IniWrite = IniWrite("_config.ini", "SETUP", "key", $handle__) $IniRead = IniRead("_config.ini", "SETUP", "key", "") ; $handle_read = FileOpen($IniRead, 0) $SaveLog = FileOpen("Results.log", 1) ; If $handle_read <> -1 Then While 1 $string = FileReadLine($handle_read) If @error Then ExitLoop $pcap = StringRegExp($string, 'UBX|FLN| (.*?)@yahoo.com\z', 3) For $i = 0 To UBound($pcap) - 1 TrayTip("Results!", $pcap[$i], 15, 1) FileWrite($SaveLog, $pcap[$i] & @CRLF) Next WEnd FileClose($handle_read) FileClose($SaveLog) Else MsgBox(0, '', 'File open error') EndIf -
DCCD reacted to SmOke_N in replace multiple strings in 100mb file
I'm sorry, I don't see the relevance to your statement/reply.
Edit:
This would speed up your script exponentially.
#include <File.au3> $path = @ScriptDir & '\xmlfo.xml' $OXML = FileOpen($path, 256) $XML = FileRead($OXML) FileClose($OXML) $term = 'post' $nofr = 1 Local $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 3) If Not @error Then For $i = 0 To UBound($aArray) - 1 ;get data start ;ConsoleWrite ( $aArray[0] &' '&$i& @CRLF) $date = StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 3) If @error Then $date = StringRegExp("date err", "(.{33,}?(?:\s)|.+)", 3) ElseIf Not @error Then ;ConsoleWrite($date[0] & ' ' & $i & @CRLF) EndIf $kind = StringRegExp($aArray[$i], '(?i)<category>(.*?)</category>', 3) If @error Then $kind = StringRegExp("kind err", "(.{33,}?(?:\s)|.+)", 3) ;ConsoleWrite ( $kind[0] &' '&$i& @CRLF) ElseIf Not @error Then ;ConsoleWrite ( $kind[0] &' '&$i& @CRLF) EndIf If $kind[0] = $term And Data(getdate($date[0], 'year'), getdate($date[0], 'month')) = True Then $XML = StringReplace($XML, $aArray[$i], '') ;_ReplaceStringInFile($path, $aArray[$i], '') If Not @error Then ;MsgBox(16,'',$XL) ConsoleWrite($nofr & ' ' & $i & @CRLF) $nofr = $nofr + 1 EndIf ;FileDelete(@ScriptDir & '\XML_output.xml') ;FileWrite (@ScriptDir & '\XML_output.xml', StringToBinary ( StringReplace($temp, $aArray[$i], "") , 4) ) Else ConsoleWrite ('err0x0'& @CRLF) EndIf Next EndIf Global $ghOpen = FileOpen($path, $FO_UTF8_NOBOM + $FO_OVERWRITE) FileWrite($ghOpen, $XML) FileClose($ghOpen) Here, as suggested before, we are only opening the file, reading the file, and writing to the file 1 time.
Your way, it was opening, reading to memory, writing as many times as the loop was long.
One thing is different, the FileOpen at the bottom of the script, you never told _ReplaceStringInFile how to write the data back to the file, so it was writing it regularly, I added $FO_UTF8_NOBOM strictly because that's how you opened it before in your code example.
So you may want to backup your xml file before using this code (just FYI).
-
DCCD reacted to SmOke_N in replace multiple strings in 100mb file
You're going to have us guess without your code and an example file of what you've tried aren't you ... ?
-
-
DCCD reacted to SmOke_N in I need help - StringRegExp
From your example, it's going to fail for us, you only provided 1 entry. The return is the number of characters, then you ask it to search from that return on. Anyway.... The first regex works for me when I double your xml example.
The ConsoleWrite(StringRegExp()) ... You know that it returns an array right? Offset doesn't apply to that for/loop because you're accessing the data directly from the array.
So this should work if you're validating only:
ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 0) & @CRLF) -
DCCD reacted to jguinch in I need help - StringRegExp
The last StringRegExp should return an array, not a string.
You should use ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1, $nOffset)[0]) instead, but in your case, $nOffset is out of range.
I don't really understand why you want to use $nOffset for, but maybe this code would match with your need :
Local $XML = FileRead(@ScriptDir & '\default.xml') Local $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 3) If NOT @error Then For $i = 0 To UBound($aArray) - 1 $aPublisher = StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1) ConsoleWrite ( $aPublisher[0] ) Next EndIf -
DCCD got a reaction from Fubarable in Include source after copmpiling
let's say you wanna put your code in a text file called 'Test.txt'
To run the code in Test.txt use this
$TextFile = "Test.txt" RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript ' & $TextFile)
You have to see Running Scripts in the help file