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

what is the proper regex to check for a gmail address

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 586 Views
  • 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 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.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
      1
      • N Natural_Bugger

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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
        1
        • JonBJ JonB

          @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 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
          • Christian EhrlicherC Christian Ehrlicher

            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 last edited by
            #5

            @Christian-Ehrlicher

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

            1 Reply Last reply
            0
            • KH-219DesignK Offline
              KH-219DesignK Offline
              KH-219Design
              wrote on 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

              • Login

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