Some more RegEx help please?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Some more RegEx help please?

Post by PepeLapiu » 02 Aug 2022, 21:16

Hey guys! My script is looking good. And I have you guys to thank for this. Your help is so appreciated!
Anyways, the following is the content of a chat exchange copied into the clipboard:
My first message
7/29/2022, 5:23:46 PM

Your first message
7/29/2022, 5:24:14 PM

My second message
7/29/2022, 5:24:19 PM

Your second message
7/29/2022, 5:24:31 PM
What I need is in two parts. First I need to get the content of the last message (in this case it's "Your second message") stored into Var_Last_Message.
Each message is separated by a time stamp. So I would need to fetch the message between the last two time stamps.

The second part is a bit trickier, I think. This last message is expected to contain a 10 digit North American phone number. So I need to fetch that phone number and store it into Var_Phone_Number with the following format: XXX-XXX-XXXX.
Problem is, I am not sure if the user will provide his number in the format above. He might use 1-(XXX) XXX-XXXX or 1-XXX-XXX-XXX or XXXXXXXXXX or any other format for phone numbers.

So I am guessing maybe a way to count how many digits are contained in the string. Making sure at least 10 digits are in there. And re-arranging the last 10 of them into the XXX-XXX-XXXX format.

Thank you all in advance for your wonderful help.

Cheers,
Pepe
Last edited by PepeLapiu on 02 Aug 2022, 23:48, edited 1 time in total.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 02 Aug 2022, 23:47

Actually, I am just going to keep asking until the user provides the correct format of XXX-XXX-XXXX (with each X being a digit).
So from the Var_Last_Message, how do I extract the numbers substring into Var_Phone_Number?

Rohwedder
Posts: 7556
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Some more RegEx help please?

Post by Rohwedder » 03 Aug 2022, 00:50

Hallo,
try:

Code: Select all

ClipBoard =
(
My first message
7/29/2022, 5:23:46 PM

Your first message
7/29/2022, 5:24:14 PM

My second message
7/29/2022, 5:24:19 PM

Your second message
123-456-7890
7/29/2022, 5:24:31 PM
)
IF RegExMatch(ClipBoard, "\d{3}-\d{3}-\d{4}", Var_Phone_Number)
	MsgBox,% Var_Phone_Number
or:

Code: Select all

Loop,% 10 Phone:="" ;10 digit North American phone number
	Phone .= "\d[-() ]*"
ClipBoard =
(
My first message
7/29/2022, 5:23:46 PM 1-(23)  456-7890
Your first message
1-23 456- 7890 7/29/2022, 5:24:14 PM
My second message
7/29/2022,123-456-78901234567890 5:24:19 PM
Your second message
7/29/2022, 5:24:31 PM 123- 456-7890
)
Pos := 1, Var_Phone_Number := ""
While, Pos := RegExMatch(ClipBoard, Phone, Var_Phone_Number, Pos+StrLen(Var_Phone_Number))
	MsgBox,% Var_Phone_Number

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 03 Aug 2022, 02:08

Rohwedder wrote:
03 Aug 2022, 00:50
Hallo,
try:

Code: Select all

ClipBoard =
(
My first message
7/29/2022, 5:23:46 PM

Your first message
7/29/2022, 5:24:14 PM

My second message
7/29/2022, 5:24:19 PM

Your second message
123-456-7890
7/29/2022, 5:24:31 PM
)
IF RegExMatch(ClipBoard, "\d{3}-\d{3}-\d{4}", Var_Phone_Number)
	MsgBox,% Var_Phone_Number
or:

Code: Select all

Loop,% 10 Phone:="" ;10 digit North American phone number
	Phone .= "\d[-() ]*"
ClipBoard =
(
My first message
7/29/2022, 5:23:46 PM 1-(23)  456-7890
Your first message
1-23 456- 7890 7/29/2022, 5:24:14 PM
My second message
7/29/2022,1234567890123-456-7890 5:24:19 PM
Your second message
7/29/2022, 5:24:31 PM 123- 456-7890
)
Pos = -9
While, Pos := RegExMatch(ClipBoard, Phone, Var_Phone_Number, Pos+10)
	MsgBox,% Var_Phone_Number
Thank you kindly. I will try them as soon as I get to my PC in the morning. But I am confused about the second suggestion.
The phone number would appear between time stamps, not as part of the time stamps. It will always be found between time stamps and only the one between the bottom two time stamps should be acceptable. So why do you have the number mixed in with the time stamps, and not in the message itself?

Rohwedder
Posts: 7556
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Some more RegEx help please?

Post by Rohwedder » 03 Aug 2022, 02:15

Just to make it harder for the RegEx so it doesn't get bored. :)

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 03 Aug 2022, 14:09

Thanx.
These two lines of code you wrote worked perfectly for me:

Code: Select all

IF RegExMatch(ClipBoard, "\d{3}-\d{3}-\d{4}", Var_Phone_Number)
	MsgBox,% Var_Phone_Number
Rohwedder wrote:
03 Aug 2022, 02:15
Just to make it harder for the RegEx so it doesn't get bored. :)
It's all well and good, but it doesn't really help.

I also need to extract the content of the last message, whatever string is contained between the bottom two time stamps. So if the clipboard reads as follows:
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message]
7/29/2022, 5:24:14 PM"
I would need a way to get the content of the last message into Var_Last_Message

Rohwedder
Posts: 7556
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Some more RegEx help please?

Post by Rohwedder » 04 Aug 2022, 02:44

Then perhaps?:

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)
IF RegExMatch(ClipBoard, "\d{3}-\d{3}-\d{4}", Var_Phone_Number)
{
	Pos := 1, Message := ""
	While, Pos := RegExMatch(ClipBoard, "(.+?)\v+\d{1,2}/\d{1,2}/\d{4}\V*", Message, Pos+StrLen(Message))
		Var_Last_Message := Trim(Message1," `t`r`n")
}
MsgBox,% Var_Phone_Number "`n" Var_Last_Message
Anyone with all five senses should also learn the five basic skills: Speaking, reading, writing, calculating and regexing!

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: Some more RegEx help please?

Post by boiler » 04 Aug 2022, 03:32

Rohwedder wrote: Anyone with all five senses should also learn the five basic skills: Speaking, reading, writing, calculating and regexing!
OP has made it clear in other threads that he cannot and will not learn RegEx, so he will ask you to adjust your code for each new variant of the haystack that he will subsequently post.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 04 Aug 2022, 07:26

boiler wrote:
04 Aug 2022, 03:32
OP has made it clear in other threads that he cannot and will not learn RegEx, so he will ask you to adjust your code for each new variant of the haystack that he will subsequently post.
You are making that up. Please provide pertinent quotes of me stating I can nt and will not learn RegEx.

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: Some more RegEx help please?

Post by boiler » 04 Aug 2022, 07:47

I did not make it up. Here is where you said you had too much on your plate to learn RegEx yourself and were just looking to have others write it for you:
viewtopic.php?f=76&t=98362&p=443962#p443962
Not saying you won’t ever learn it, but you are not posting to try to learn it — you are wanting someone to write it. Just pointing that out since Rohwedder made a point about learning it.

And here is where you said you could not learn the much easier concept of expressions because the manual is in English, not French:
viewtopic.php?style=17&p=443127#p443531

I apologize if recalling you making statements like that has led me to mischaracterize your position.

Descolada
Posts: 1102
Joined: 23 Dec 2021, 02:30

Re: Some more RegEx help please?

Post by Descolada » 04 Aug 2022, 09:09

Perhaps this would work also?

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && RegExMatch(Var_Last_Message := StrReverse(match1), "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10))
	MsgBox, % Var_Phone_Number

StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 04 Aug 2022, 10:22

Descolada wrote:
04 Aug 2022, 09:09
Perhaps this would work also?

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && RegExMatch(Var_Last_Message := StrReverse(match1), "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10))
	MsgBox, % Var_Phone_Number

StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
Thank you but I think you are giving me too much here. I just want to extract the last message in the thread into a variable without worrying about a phone number for the moment. The last message would be between the last two time stamps.
So would this work?
if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match)
And how would I store the last message into Var_Last_Message ?

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 04 Aug 2022, 10:31

So please forget all previous information.
Right now, all I want to do is take the clipboard content, a sample of which is quoted here:
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
And I want to store the last message into a variable Var_Last_Message. The last message will always be between the last two time stamps.

Descolada
Posts: 1102
Joined: 23 Dec 2021, 02:30

Re: Some more RegEx help please?

Post by Descolada » 04 Aug 2022, 11:35

@PepeLapiu, my example actually also contains the variable Var_Last_Message. Is it not what you wanted?

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 04 Aug 2022, 12:22

Descolada wrote:
04 Aug 2022, 11:35
@PepeLapiu, my example actually also contains the variable Var_Last_Message. Is it not what you wanted?
Well, for some reason the code you wrote doesn't work at all for me.
Can you do it in two lines of code? One line of code to extract the last message from the clipboard into Var_Last_Massage and on line of code to extract the phone number out of Var_Last_Message ?
Kinda like this:

Code: Select all

[Your RegEx code]
MsgBox, % Var_Last_Message ; extracted from clipboard
IF RegExMatch(Var_Last_Message, "\d{3}-\d{3}-\d{4}", Var_Phone_Number)
	MsgBox,%  Var_Phone_Number  ; extracted from Var_Last_Message
I really struggle with RegEx. Maybe if you feed it to me in bite size, I can understand it better?

Descolada
Posts: 1102
Joined: 23 Dec 2021, 02:30

Re: Some more RegEx help please?

Post by Descolada » 04 Aug 2022, 13:55

@PepeLapiu, in my code

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && RegExMatch(Var_Last_Message := StrReverse(match1), "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-. ,]"), -9, 10))
	MsgBox, % Var_Phone_Number

StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
The first part RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) uses the function StrReverse to reverse the string, then matches all the text between the first two dates (which are actually the last two dates, since we reversed the string). The text in the middle will be inside match1, but in reverse.

Then with RegExMatch(Var_Last_Message := StrReverse(match1), "(?:\d[+\-)(., ]*)+", Var_Phone_Number) we reverse match1 to get the content in correct form and store it in Var_Last_Message. Then we RegexMatch for all numbers that are separated only by any of these characters: +\-)(. ,.

The last part (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10)) will remove all the unwanted characters (+\-)(. ,), and then take the last 10 digits from there (which should be the phone number).

I'm not sure what you mean by "didn't work at all for me". Did it throw an error? Did you include the last bit as well containing StrReverse?

Code: Select all

StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
In two lines:

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Var_Last_Message := StrReverse(match1))
	MsgBox, % Var_Last_Message
if RegExMatch(Var_Last_Message, "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10))
	MsgBox, % Var_Phone_Number
StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}

sofista
Posts: 645
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Some more RegEx help please?

Post by sofista » 04 Aug 2022, 14:39

PepeLapiu wrote:
04 Aug 2022, 10:31
So please forget all previous information.
Right now, all I want to do is take the clipboard content, a sample of which is quoted here:
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
And I want to store the last message into a variable Var_Last_Message. The last message will always be between the last two time stamps.

Although you asked for a RegEx solution, I would like to propose this other approach, maybe it will be easier to grasp

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

Var_Phone_Number := (arr := StrSplit(Clipboard, "`n"))[arr.Count()-1]
MsgBox, % Var_Phone_Number    ; [Your answer or content of last message 123-456-7890]

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 06 Aug 2022, 21:20

Descolada wrote:
04 Aug 2022, 13:55
@PepeLapiu, in my code

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && RegExMatch(Var_Last_Message := StrReverse(match1), "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-. ,]"), -9, 10))
	MsgBox, % Var_Phone_Number

StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
The first part RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) uses the function StrReverse to reverse the string, then matches all the text between the first two dates (which are actually the last two dates, since we reversed the string). The text in the middle will be inside match1, but in reverse.

Then with RegExMatch(Var_Last_Message := StrReverse(match1), "(?:\d[+\-)(., ]*)+", Var_Phone_Number) we reverse match1 to get the content in correct form and store it in Var_Last_Message. Then we RegexMatch for all numbers that are separated only by any of these characters: +\-)(. ,.

The last part (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10)) will remove all the unwanted characters (+\-)(. ,), and then take the last 10 digits from there (which should be the phone number).

I'm not sure what you mean by "didn't work at all for me". Did it throw an error? Did you include the last bit as well containing StrReverse?

Code: Select all

StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
In two lines:

Code: Select all

ClipBoard =
(
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
)

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Var_Last_Message := StrReverse(match1))
	MsgBox, % Var_Last_Message
if RegExMatch(Var_Last_Message, "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10))
	MsgBox, % Var_Phone_Number
StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
By not working for me, I mean that I was running the script you provided and nothing would happen. And the same thing occurs with your new code.
Here is the clipboard I kept in quote:
[Hi or content of first message]
7/29/2022, 5:23:46 PM

[Hello or content of second message]
7/29/2022, 5:24:14 PM"

[My question or content of third message]
7/29/2022, 5:23:46 PM

[Your answer or content of last message 123-456-7890]
7/29/2022, 5:24:14 PM"
And here is the script I tried to run while the clipboard was loaded with the stuff quoted above:

Code: Select all

if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Var_Last_Message := StrReverse(match1))
	MsgBox, % Var_Last_Message
if RegExMatch(Var_Last_Message, "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10))
	MsgBox, % Var_Phone_Number
StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
Simply put, running the script did not produce an error. It simply did nothing. So I altered it like so:

Code: Select all

MsgBox, Go
if RegExMatch(StrReverse(ClipBoard), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Var_Last_Message := StrReverse(match1))
	MsgBox, % Var_Last_Message
if RegExMatch(Var_Last_Message, "(?:\d[+\-)(., ]*)+", Var_Phone_Number) && (Var_Phone_Number := SubStr(RegexReplace(Var_Phone_Number, "[)(+-., ]"), -9, 10))
	MsgBox, % Var_Phone_Number
StrReverse(String) {
	String .= "", DllCall("msvcrt.dll\_wcsrev", "Ptr", &String, "CDecl")
    return String
}
MsgBox, End of script
Again, nothing happened. Not even a window popping up saying "Go". Nothing at all happened.

Edit: I have no idea why it was not working. And I have no idea why it suddenly started to work. And your code worked perfectly. Thank you very much!

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Some more RegEx help please?

Post by PepeLapiu » 09 Aug 2022, 22:24

@Descolada
Just a little update. Sometimes your code worked beautifully, other times it didn't work at all. I could spend half a day with the code doing what it was supposed to do, than suddenly stop working at all for no apparent reason.

Until I realized your code only worked in the afternoon, never in the morning. And so this is how I fixed it. Probably there are more elegant ways to do it but it works perfect that way now:

Code: Select all

RegExMatch(StrReverse(chat_copy), "MA \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MA \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Last_Message := StrReverse(match1))
If(Last_Message="")
	RegExMatch(StrReverse(chat_copy), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Last_Message := StrReverse(match1))
If(Last_Message="")
	RegExMatch(StrReverse(chat_copy), "MA \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Last_Message := StrReverse(match1))
If(Last_Message="")
	RegExMatch(StrReverse(chat_copy), "MP \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)MA \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?", match) && (Last_Message := StrReverse(match1))

Descolada
Posts: 1102
Joined: 23 Dec 2021, 02:30

Re: Some more RegEx help please?

Post by Descolada » 09 Aug 2022, 23:29

@PepeLapiu, M[AP] \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d?([\w\W]*?)M[AP] \d\d:\d\d:\d\d? ,\d{4}\/\d\d?\/\d\d? should work as well. RegEx is tricky this way, need to account for all sorts of things ;)

Post Reply

Return to “Ask for Help (v1)”