@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
}