How to skip an unmatched line in input on replacing by regex?
For Ex. Below is the contents of my test.txt
[email protected]
[email protected]
elke engineering ltd.,@yahoo.com
[email protected]
[email protected]
Below is my Autohotkey script with regex code
ReplaceEmailsRegEx := "i)([a-z0-9]+(\.*|\_*|\-*))+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}"
RemoveDuplicateCharactersRegEx := "s)(.)(?=.*\1)"
Try{
FileRead, EmailFromTxtFile, test.txt
OtherThanEmails :=RegExReplace(EmailFromTxtFile,ReplaceEmailsRegEx)
Chars :=RegExReplace(OtherThanEmails,RemoveDuplicateCharactersRegEx)
Loop{
StringReplace, OtherThanEmails, OtherThanEmails, `r`n`r`n,`r`n, UseErrorLevel
If ErrorLevel = 0
Break
}
If (StrLen(OtherThanEmails)){
Msgbox The Characters found other than email:`n%OtherThanEmails%
}
}
catch e {
ErrorString:="what: " . e.what . "file: " . e.file . " line: " . e.line . " msg: " . e.message . " extra: " . e.extra
Msgbox An Exception was thrown`n%ErrorString%
}
Return
When it replace on test.txt it throws error:
e.what contains 'RegExReplace', e.line is 10
It executes without error when I remove 3rd email in test.txt. So how to change my regex to skip the problematic string?
i)[a-z0-9]+(?:(?:\.+|_+|-+)[a-z0-9]+)*@([a-z][-a-z0-9]+\.)+[a-z]{2,6}. Ori)[a-z0-9]+(?:([._-])\1*[a-z0-9]+)*@([a-z][-a-z0-9]+\.)+[a-z]{2,6}- Wiktor Stribiżew