Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Looking for pattern

[Solved] Looking for pattern

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ninio
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • N Offline
      N Offline
      ninio
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerManu
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • N Offline
            N Offline
            ninio
            wrote on last edited by
            #5

            [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?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on last edited by
              #6

              [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.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tobias.hunger
                wrote on last edited by
                #7

                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:-)

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved