Cormin Posted January 22, 2017 Posted January 22, 2017 (edited) My script currently reads a text file line by line. I want it to look for this the chat message below and skip the session messages. Quote Session Close: Sun Jan 22 02:00:35 2017 Session Start: Sun Jan 22 10:14:57 2017 [10:15] <Cormin> heres my chat message There are some garbage lines that I want it to skip over. So if a line doesnt match that format then skip it. I tried experimenting with StringRegExp but I think I'm using it wrong. Heres my code If StringRegExp($read, '\W\d\d\w\d\d\D.\W') = Not @error Then I was hoping that this would be able to see the open bracket, 2 digits, a colon, 2 digits, close bracket, a space and a <. But it doesn't seem to be working. Eventually I want to be able to extract the username and chat message into separate strings but I haven't got that far yet. Edited January 22, 2017 by Cormin
Cormin Posted January 22, 2017 Author Posted January 22, 2017 Local $text = StringRegExp($read2, '[:ascii:][:digit:][:digit:][:ascii:][:digit:][:digit:]]*?') I've tried this too but it just always returns a 0 for every line that isnt blank.
Moderators Melba23 Posted January 22, 2017 Moderators Posted January 22, 2017 Cormin, This works for me: #include <Array.au3> #include <StringConstants.au3> $aLines = FileReadToArray("IRC.txt") _ArrayDisplay($aLines, "", Default, 8) Global $aExtract[UBound($aLines) - 1][2] ; Array to hold the extracted data Global $iIndex = 0 ; Index of array to fill Global $sDelim = "~~~~~" ; Choose a string that is very unlikely to appear in the message For $i = 0 To UBound($aLines) - 1 ; Loop through the lines and check if they match a message line - extract the name and the message $sExtract = StringRegExpReplace($aLines[$i], "^.*<(\w+)>\s(.*)$", "$1" & $sDelim & "$2") ; Split the line $aSplit = StringSplit($sExtract, $sDelim, $STR_ENTIRESPLIT) ; Save the the array If Not @error Then $aExtract[$iIndex][0] = $aSplit[1] $aExtract[$iIndex][1] = $aSplit[2] ; Increase the index $iIndex += 1 EndIf Next ; Correctly size the extracted array and show it ReDim $aExtract[$iIndex][2] _ArrayDisplay($aExtract, "", Default, 8) with this file: Session Close: Sun Jan 22 02:00:35 2017 Session Start: Sun Jan 22 10:14:57 2017 garbage [10:15] <Cormin> heres my chat message1 [10:15] <Cormin> heres my chat message2 garbage [10:15] <Cormin> heres my chat message3 [10:15] <Cormin> heres my chat message4 M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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