[Solved] Looking for pattern



  • I'm looking for a email pattern in a QString. This is the RegExp: \w[a-z, 0-9]+@\w[a-z, 0-9]+.\w[a-z, 0-9]+.\w[a-z, 0-9]+
    The problem is that I have not matches. And if i got matches using another pattern, I don' know how to take them from the string :/

    Edit: Ok, now, i got matches. This is the code:

    @int pos = 0, i = 0;
    while((pos = mailPattern.indexIn(src, pos)) != -1)
    {
    qDebug() << "Item: " << mailPattern.cap(i);

    pos += mailPattern.matchedLength();
    

    }@

    But it takes some tags like "<>", I would like ignore them



  • Done, just modifing the patter to: \w[a-z, 0-9, .]+@\w[a-z, 0-9, .]+



  • [quote author="ninio" date="1344989108"]Done, just modifing the patter to: \w[a-z, 0-9, .]+@\w[a-z, 0-9, .]+[/quote]

    E-Mail adresses can't contain commas nor spaces. Check the meaning of [] in regular expressions.



  • And you're missing lots of other allowed symbols in front of the @-Symbol:
    !#$%&'*+-/=?^_`{|}~

    see RFC 2822 Section 3.4.1 and RFC 5322 Section 3.2.3



  • [quote author="DerManu" date="1345011052"][quote author="ninio" date="1344989108"]Done, just modifing the patter to: \w[a-z, 0-9, .]+@\w[a-z, 0-9, .]+[/quote]

    E-Mail adresses can't contain commas nor spaces. Check the meaning of [] in regular expressions.[/quote]

    Good point, so... How can I avoid them?



  • [quote author="ninio" date="1345091334"]
    Good point, so... How can I avoid them?[/quote]

    Just like I said, learn about regular expressions, especially the "proper usage of the [] brackets":http://www.regular-expressions.info/charclass.html.


  • Moderators

    There is a regexp for email addresses available here: http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

    It is a bit longer and more complex than yours:-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.