Jump to content

StringRegExp / StringRegExpReplace...


AutID
 Share

Recommended Posts

That much i understood after reading it some hours.

This is my script.

#include <Array.au3>


Global $STEMPMESS, $STEMPUSER


Local $test = 0
Local $SLINES = "[04:27:26] <test1> ] <p2ff>" & @LF & _
"[04:27:36] <test1> par211233123azit" & @LF & _
"[04:27:36] <test1> par2112341243123azit" & @LF & _
"[04:27:39] <test1> ] <pf3f>" & @LF & _
"[04:27:55] <test2> yukiii" & @LF & _
"[04:28:23] <test2> ] ok i dont " & @LF & _
"[04:27:39] <test3> <test> par213123azit<test> par213123azit " & @LF & _
"[04:27:39] <test3> parazit123"
$SLINES = StringRegExpReplace($SLINES, "(\v+)([^\[])", "$2")
Local $ALINES = StringRegExp($SLINES, "(? :([^\v]+)(?:\v+|$))", 3)
_ArrayDisplay($ALINES)
If IsArray($ALINES) Then
Local $SRES = ""
For $I = 0 To UBound($ALINES) - 1
$test = $test + 1
$STEMPMESS = StringRegExpReplace($ALINES[$I], "(?:^.*?>|.*?\])(\h*.*?\h*)((\].*$)|$)", "$1")
For $J = 0 To UBound($ALINES) - 1
If (StringInStr($ALINES[$I], "[System Message]") = 0) And ($I <> $J) And (StringCompare($STEMPMESS, StringRegExpReplace($ALINES[$J], "(?:^.*?>|.*?\])(\h*.*?\h*)((\].*$)|$)", "$1"), 1) = 0) Then
$STEMPUSER = StringRegExpReplace($ALINES[$I], "(?:\[.*?<)(.*?)>.*$", "$1")
If $STEMPUSER == StringRegExpReplace($ALINES[$J], "(?:\[.*?<)(.*?)>.*$", "$1") Then
If $I < $J Then
If $J - $I < 4 Then
$SRES &= StringFormat('Line %3d/ is: "%s"\n', $I + 1, $ALINES[$I]) & StringFormat('Line %3d/ is: "%s"\n', $J + 1, $ALINES[$J])
ExitLoop
Else
$INUMUSERS = 0
For $K = ($I + 1) To ($J - 1)
If $STEMPUSER == StringRegExpReplace($ALINES[$K], "(?:\[.*?<)(.*?)>.*$", "$1") Then $INUMUSERS += 1
If $INUMUSERS = 3 Then
ExitLoop 2
EndIf
Next
$SRES &= StringFormat('Line %3d/ is: "%s"\n', $I + 1, $ALINES[$I]) & StringFormat('Line %3d/ is: "%s"\n', $J + 1, $ALINES[$J])
EndIf
EndIf
EndIf
EndIf
Next
Next
If $SRES = "" Then
ConsoleWrite("No user found" & @CRLF & @CRLF & $test & " lines checked." & @CRLF)
Else
ConsoleWrite(@CRLF & @CRLF & "Lines " & @CRLF & $SRES & @LF)
EndIf
Else
MsgBox(64, "Attention", $SWINTITLE & " has no lines present.", 2)
EndIf
Why this is telling me that the 1st and the 4th line are the same?

I think my problem is where i strip out the messages to compare.

This patern myst be wrong.

$STEMPMESS = StringRegExpReplace($ALINES[$I], "(?:^.*?>|.*?\])(\h*.*?\h*)((\].*$)|$)", "$1")
Edited by AutID
Link to comment
Share on other sites

Please make it clear about what you expect and where, much simpler (one regexp only) and self-contained.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Bonjour,

What i am doing is; i am checking the messages each user send. If there are messages that are exactly the same then i get the user of the messages. If between the two lines that are the same the user hasnt already written something different then i am displaying it in a msgbox as a spam and some other staff...

The problem is that it is giving me the 1st and the 4th lines are exactly the same which is not true. The error is in the $STEMPMESS @replace.

Link to comment
Share on other sites

  • Moderators

AutId,

I am afraid that is a clear as mud to me. :wacko:

Some questions:

 

- 1. How do you tell which user sent the message? Is it the <test#> section in the lines you posted above?

- 2. You say you want to detect exact copies of messages - there are no exact copies in the lines you posted, other than in this one:

"[04:27:39] <test3> <test> par213123azit<test> par213123azit

which is significantly different in format to all the others. Is that indeed what you looking for? Or could the copies be on different lines?

M23

Edited by Melba23
Typo

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

Melba thats my problem. Normally it should return false and say that there are no same message.

But it returns the 1st and the 4th lines as same messages which means my stringregexpreplace for the message is wrong...

The lines are fomated like this, first is the time in the [...] then is the user <...> and then is the message...

Link to comment
Share on other sites

  • Moderators

AutID,

When I run the code you posted I just get a an error from this line:

Local $ALINES = StringRegExp($SLINES, "(? :([^\v]+)(?:\v+|$))", 3)
telling me that the pattern is bad - so no array is generated and the main part of the script is bypassed. :(

Help us to help you by explaining what your script is doing as it moves along - at the moment we need to guess about your logic and the role of the multiple RegEx lines. Personally I am not prepared to waste my brain cells trying to decipher all your RegExes - I have enough trouble building my own and I am not prepared to try and work through someone elses. ;)

So how about you add some comments telling us what is happening (or suppposed to happen) as the script runs - then we might be able to offer some focused help. :)

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

@M23,

Local $ALINES = StringRegExp($SLINES, "(? :([^\v]+)(?:\v+|$))", 3)

is supposed to be

Local $ALINES = StringRegExp($SLINES, "(?:([^\v]+)(?:\v+|$))", 3)

.

.

.

@AutID you are only comparing the message part, irrespective of the user and time. Right ?

Plus, is the part underlined, the message?

[04:27:26] <test1> ] <p2ff>
[04:27:36] <test1> par211233123azit
[04:27:36] <test1> par2112341243123azit
[04:27:39] <test1> ] <pf3f>
[04:27:55] <test2> yukiii
[04:28:23] <test2> ] ok i dont
[04:27:39] <test3> <test> par213123azit<test> par213123azit
[04:27:39] <test3> parazit123

Note: the space after the username isn't included as per it.

if the above two hold true, the following may help

#include <Array.au3>
#include <Misc.au3>

Global $STEMPMESS, $STEMPUSER


Local $test = 0
Local $SLINES = "[04:27:26] <test1> ] <p2ff>" & @LF & _
        "[04:27:36] <test1> par211233123azit" & @LF & _
        "[04:27:36] <test1> par2112341243123azit" & @LF & _
        "[04:27:39] <test1> ] <pf3f>" & @LF & _
        "[04:27:55] <test2> yukiii" & @LF & _
        "[04:28:23] <test2> ] ok i dont " & @LF & _
        "[04:28:23] <test2> yukiii " & @LF & _
        "[04:27:39] <test3> <test> par213123azit<test> par213123azit " & @LF & _
        "[04:27:39] <test3> ] <p2ff>" & @LF & _
        "[04:27:39] <test3> parazit123" & @LF & _
        "[04:27:42] <test7> parazit123"
$SLINES = StringRegExpReplace($SLINES, "(\v+)([^\[])", "$2")

Local $ALINES = StringRegExp($SLINES, "(?:([^\v]+)(?:\v+|$))", 3)
_ArrayDisplay($ALINES)

Local $aMESSAGES = StringRegExp($SLINES, "(?m)^(?:\[.*?<.*?> )(.*?)$", 3)
_ArrayDisplay($aMESSAGES)

ConsoleWrite("Comparing Messages" & @CRLF)

Local $aTemp, $s_Ret
;Now lets compare the messages
For $i = 0 To UBound($aMESSAGES)-1

    $aTemp = _ArrayFindAll($aMESSAGES, $aMESSAGES[$i])
    If @error Or UBound($aTemp) = 1 Then ContinueLoop

    $s_Ret &= "->" & $i & " line's message matches with "
    For $n = 0 To UBound($aTemp) -1
        If $aTemp[$n] > $i Then $s_Ret &= $aTemp[$n] & ", "
    Next
    $s_Ret = _Iif(StringRight($s_Ret,2) = ", ", StringTrimRight($s_Ret, 2) & " line's message. ie " & $aMESSAGES[$i] & @CRLF, StringRegExpReplace($s_Ret, "(?m)(.*)\v+.*$", "$1"))

Next

ConsoleWrite($s_Ret)
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

This is going from bad to worst... Sorry for that.

Let me explain better. I added comment lines to the script so you can understand

#include <Array.au3>


Global $SWINTITLE = "acmm_client"
Global $STEMPMESS, $STEMPUSER


Local $test = 0
Local $SLINES = "[04:27:26] <user1> ] message1" & @LF & _
"[04:27:36] <user1> message123" & @LF & _
"[04:27:36] <user1> message543" & @LF & _
"[04:27:39] <user1> ] message3312" & @LF & _
"[04:27:55] <user2> message2" & @LF & _ ;TEXT
"[04:28:23] <user2> ] message4 " & @LF & _
"[04:27:39] <user3> message8 " & @LF & _
"[04:27:39] <user3> message5"
$SLINES = StringRegExpReplace($SLINES, "(\v+)([^\[])", "$2") ;Remove vertical spaces exept [
Local $ALINES = StringRegExp($SLINES, "(?:([^\v]+)(?:\v+|$))", 3) ;Return the valid array
_ArrayDisplay($ALINES)
If IsArray($ALINES) Then
Local $SRES = ""
For $I = 0 To UBound($ALINES) - 1 ; Count lines
$test = $test + 1
$STEMPMESS = StringRegExpReplace($ALINES[$I], "(?:^.*?>|.*?\])(\h*.*?\h*)((\].*$)|$)", "$1") ;Get the message of each line
For $J = 0 To UBound($ALINES) - 1 ;Count lines
If (StringInStr($ALINES[$I], "[System Message]") = 0) And ($I <> $J) And (StringCompare($STEMPMESS, StringRegExpReplace($ALINES[$J], "(?:^.*?>|.*?\])(\h*.*?\h*)((\].*$)|$)", "$1"), 1) = 0) Then
;If [System Message] doesn't exists between the two same linece, if there are two different lines with the same message, If the two messages are exactly the same
$STEMPUSER = StringRegExpReplace($ALINES[$I], "(?:\[.*?<)(.*?)>.*$", "$1") ;Then get the users of the messages that are exactly the same
If $STEMPUSER == StringRegExpReplace($ALINES[$J], "(?:\[.*?<)(.*?)>.*$", "$1") Then ;If the two users are the same, means that the user is 1 and is sending the same message twice
If $I < $J Then
If $J - $I < 4 Then ;If there are less than 4 lines between the two same messages
$SRES &= StringFormat('Line %3d/ is: "%s"\n', $I + 1, $ALINES[$I]) & StringFormat('Line %3d/ is: "%s"\n', $J + 1, $ALINES[$J]) ;Get the line
ExitLoop
Else
$INUMUSERS = 0
For $K = ($I + 1) To ($J - 1) ;Count lines between the 2 same messages
If $STEMPUSER == StringRegExpReplace($ALINES[$K], "(?:\[.*?<)(.*?)>.*$", "$1") Then $INUMUSERS += 1 ;Count the user
If $INUMUSERS = 3 Then ;If the user has sent the different messages between the two same messages then dont get the line.
ExitLoop 2
EndIf
Next
$SRES &= StringFormat('Line %3d/ is: "%s"\n', $I + 1, $ALINES[$I]) & StringFormat('Line %3d/ is: "%s"\n', $J + 1, $ALINES[$J])
EndIf
EndIf
EndIf
EndIf
Next
Next
If $SRES = "" Then
ConsoleWrite("No user found" & @CRLF & @CRLF & $test & " lines checked." & @CRLF)
Else
ConsoleWrite(@CRLF & @CRLF & "Lines " & @CRLF & $SRES & @LF)
EndIf
Else
MsgBox(64, "Attention", $SWINTITLE & " has no lines present.", 2)
EndIf

1st: Remove vertical spaces besides [

2ond: Return a valid array

3rd: Count the lines

4th: Get message of each line

5th: Count lines again

6th: Get the messages again and check if they are in different lines, if the text "[system Message]" exists between the two same lines and if the two messages are exactly the same

7th: If 6th is true then get the user of the two same messages

8th: Check if the two same messages have the same user which means that the user is 1 and has sent the same message twice

9th: If 8th is true then check if there are less than 4 different lines with the same user between the two same messages

Link to comment
Share on other sites

Well got that thing working. As i was saying my patern for the message was wrong. I used the patern @PhoenixXL used for the message and it is working ;)

Thank you guys and sorry for the troubles...

#include <Array.au3>


Global $SWINTITLE = "acmm_client"
Global $STEMPMESS, $STEMPUSER


Local $test = 0
Local $SLINES = "[04:27:26] <user1> ] message1" & @LF & _
"[04:27:36] <user1> message123" & @LF & _
"[04:27:36] <user1> message543" & @LF & _
"[04:27:39] <user1> ] message1" & @LF & _
"[04:27:55] <user2> message2" & @LF & _ ;TEXT
"[04:28:23] <user2> ] message4 " & @LF & _
"[04:27:39] <user3> message8 " & @LF & _
"[04:27:39] <user3> message5"
$SLINES = StringRegExpReplace($SLINES, "(\v+)([^\[])", "$2") ;Remove vertical spaces exept [
Local $ALINES = StringRegExp($SLINES, "(?:([^\v]+)(?:\v+|$))", 3) ;Return the valid array
If IsArray($ALINES) Then
Local $SRES = ""
For $I = 0 To UBound($ALINES) - 1 ; Count lines
$test = $test + 1
$STEMPMESS = StringRegExpReplace($ALINES[$I], "(?m)^(?:\[.*?<.*?> )(.*?)$", "$1") ;Get the message of each line
For $J = 0 To UBound($ALINES) - 1 ;Count lines
If (StringInStr($ALINES[$I], "[System Message]") = 0) And ($I <> $J) And (StringCompare($STEMPMESS, StringRegExpReplace($ALINES[$J], "(?m)^(?:\[.*?<.*?> )(.*?)$", "$1"), 1) = 0) Then
;If [System Message] doesn't exists between the two same linece, if there are two different lines with the same message, If the two messages are exactly the same
$STEMPUSER = StringRegExpReplace($ALINES[$I], "(?:\[.*?<)(.*?)>.*$", "$1") ;Then get the users of the messages that are exactly the same
If $STEMPUSER == StringRegExpReplace($ALINES[$J], "(?:\[.*?<)(.*?)>.*$", "$1") Then ;If the two users are the same, means that the user is 1 and is sending the same message twice
If $I < $J Then
If $J - $I < 4 Then ;If there are less than 4 lines between the two same messages
$SRES &= StringFormat('Line %3d/ is: "%s"\n', $I + 1, $ALINES[$I]) & StringFormat('Line %3d/ is: "%s"\n', $J + 1, $ALINES[$J]) ;Get the line
ExitLoop
Else
$INUMUSERS = 0
For $K = ($I + 1) To ($J - 1) ;Count lines between the 2 same messages
If $STEMPUSER == StringRegExpReplace($ALINES[$K], "(?:\[.*?<)(.*?)>.*$", "$1") Then $INUMUSERS += 1 ;Count the user
If $INUMUSERS = 3 Then ;If the user has sent the different messages between the two same messages then dont get the line.
ExitLoop 2
EndIf
Next
$SRES &= StringFormat('Line %3d/ is: "%s"\n', $I + 1, $ALINES[$I]) & StringFormat('Line %3d/ is: "%s"\n', $J + 1, $ALINES[$J])
EndIf
EndIf
EndIf
EndIf
Next
Next
If $SRES = "" Then
ConsoleWrite("No user found" & @CRLF & @CRLF & $test & " lines checked." & @CRLF)
Else
ConsoleWrite(@CRLF & @CRLF & "Lines " & @CRLF & $SRES & @LF)
EndIf
Else
MsgBox(64, "Attention", $SWINTITLE & " has no lines present.", 2)
EndIf
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...