Jump to content

Recommended Posts

Posted

Hello ..

hello guys!
I need your help a few minutes!

I have a maney text file, how could an algorithm, to extract only the email addresses those that contain "." and "@"

If you can help me, I'll be very grateful, thank you!

Posted

Take a look to this page, you will find several regular expresions (explained) to match email addresses. One you get the right one, you can use it on autoit using StringRegExp or StringRegExpReplace functions.

Posted

Not working for me :sweating:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 251, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 8, 593, 169, $ES_WANTRETURN)
GUICtrlSetData(-1, StringFormat("As I explain below, my claim only holds true testmail@mail.com when one accepts my definition of what a valid email \r\naddress really is, and what \r\nit" & Chr(39) & "s not. If you want to use a different definition, you" & Chr(39) & "ll have to adapt the mail2@gmail.com regex. Matching a valid email \r\naddress is a perfect \r\nexample showing that before writing m3@ts1.es a regex, you have to know exactly what you" & Chr(39) & "re trying to match, and what \r\nnot; and \r\nthere" & Chr(39) & "s often a trade-off between what" & Chr(39) & "s exact, and what" & Chr(39) & "s practical."))
$Button1 = GUICtrlCreateButton("Show emails", 16, 192, 419, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $aArray = StringRegExp(GUICtrlRead($Edit1), '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b', $STR_REGEXPARRAYMATCH)
            For $i = 0 To UBound($aArray) - 1
                MsgBox(0, "" & $i, $aArray[$i])
            Next

            #cs
            RESULT:
            testmail@mail.com
            mail2@gmail.com
            m3@ts1.es
            #ce
    EndSwitch
WEnd

probably am wrong somewhere....

Posted (edited)

In the sets you use A-Z which matches uppercase while the mail addresses are lowercase, so you must make the regex case insensitive using (?i)

BTW better use  $STR_REGEXPARRAYGLOBALMATCH  to get all the matches instead of  $STR_REGEXPARRAYMATCH  which returns only the first one

Edited by mikell
  • Solution
Posted (edited)

Not working for me :sweating:

 

mikell pointed to the the solution to solve your problem. You have two options, make the search case insensitive

$aArray = StringRegExp(GUICtrlRead($Edit1), '(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b',  $STR_REGEXPARRAYGLOBALMATCH)

or add a-z to the pattern to match lowercase letters.

$aArray = StringRegExp(GUICtrlRead($Edit1), '\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b',  $STR_REGEXPARRAYGLOBALMATCH)

Anyway, in the page I linked yesterday, you had this info ;) "If you want to use the regular expression above, there's two things you need to understand. First, long regexes make it difficult to nicely format paragraphs. So I didn't include a-z in any of the three character classes. This regex is intended to be used with your regex engine's "case insensitive" option turned on."

Cheers,

sahsanu

Edited by sahsanu

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
  • Recently Browsing   0 members

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