Jump to content

Parsing IRC Chat


Cormin
 Share

Recommended Posts

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 by Cormin
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...