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. what is the proper regex to check for a gmail address
Forum Updated to NodeBB v4.3 + New Features

what is the proper regex to check for a gmail address

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 610 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
    Natural_Bugger
    wrote on 17 Aug 2020, 11:55 last edited by Natural_Bugger
    #1

    Hello,

    i only need to check if it contains "gmail.com" after the @, anything before doesn't matter

    i found various, but none did the job.

    smatch match;
                    regex r("gmail.com");
                    if(regex_search(iter->second, match, r)){
                    std::cout << iter->first << std::endl;
                    }
    

    this doesn't cut the mostard.

    alice alice@alicegmail.com
    alice alice@gmail.com
    

    regards.

    J 1 Reply Last reply 17 Aug 2020, 11:56
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 17 Aug 2020, 11:56 last edited by
      #2

      And why in 'C++ Gurus'? Doing a simply QString::endsWidth() so hard to need a c++ guru?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      N 1 Reply Last reply 17 Aug 2020, 12:06
      1
      • N Natural_Bugger
        17 Aug 2020, 11:55

        Hello,

        i only need to check if it contains "gmail.com" after the @, anything before doesn't matter

        i found various, but none did the job.

        smatch match;
                        regex r("gmail.com");
                        if(regex_search(iter->second, match, r)){
                        std::cout << iter->first << std::endl;
                        }
        

        this doesn't cut the mostard.

        alice alice@alicegmail.com
        alice alice@gmail.com
        

        regards.

        J Online
        J Online
        JonB
        wrote on 17 Aug 2020, 11:56 last edited by JonB
        #3

        @Natural_Bugger
        So did you try ^.*@gmail\.com$?

        Though as @Christian-Ehrlicher says, as stated by you it doesn't need a regular expression anyway.

        N 1 Reply Last reply 17 Aug 2020, 12:05
        1
        • J JonB
          17 Aug 2020, 11:56

          @Natural_Bugger
          So did you try ^.*@gmail\.com$?

          Though as @Christian-Ehrlicher says, as stated by you it doesn't need a regular expression anyway.

          N Offline
          N Offline
          Natural_Bugger
          wrote on 17 Aug 2020, 12:05 last edited by
          #4

          @JonB

          thnks for your answer and it worked out.
          haven't touched regex in years or decenia.

          that is the assignment, use regex.

          1 Reply Last reply
          0
          • C Christian Ehrlicher
            17 Aug 2020, 11:56

            And why in 'C++ Gurus'? Doing a simply QString::endsWidth() so hard to need a c++ guru?

            N Offline
            N Offline
            Natural_Bugger
            wrote on 17 Aug 2020, 12:06 last edited by
            #5

            @Christian-Ehrlicher

            sorry, i didn't know what was the right section.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KH-219Design
              wrote on 17 Aug 2020, 17:23 last edited by
              #6

              Please feel free to ignore me if I am "overthinking" the nature of your task...

              I'm wondering why exactly anyone would filter precisely and exclusively "gmail.com" addresses. One answer that immediately comes to mind is the use case where you want to use Google OAuth. The user would (I believe) need a provided-by-google email account to participate in Google OAuth. However, filtering by "gmail.com" is overly restrictive for that case. When a business uses Google as their email provider, you can have "me@mybusiness.com" provided under-the-hood by Gmail.

              www.219design.com
              Software | Electrical | Mechanical | Product Design

              1 Reply Last reply
              0

              1/6

              17 Aug 2020, 11:55

              • Login

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