C++ || STL || standard template libraries

Image
                                       C++ STL  1.      Pair :  Syntax :      pair <int,char> p1;     it creates a pair {2,'c'} like this.           pair <int,int> p2;     it creates a pair {2,3} like this .  Basic Code :  #include <bits/stdc++.h> using namespace std; int main() {     // cout<<"hello world\n";     pair <int,int> p1 = {1,2};     cout<<p1.first<< " "<< p1.second<<endl;          pair <int, pair<int ,char>> p2 = {1,{2,'c'}};     cout<<p2.first<<" "<<p2.second.first<<" "<<p2.second.second<<endl;          pair <int,int> arr[] = {{2,3},{4,5},{6,7}};     cout...

Find Users With Valid E-Mails || Leetcode sql solution || Easy solution || Fully-Explained || 💯💯💯✅✅✅🔥🔥🔥

 

1517. Find Users With Valid E-Mails



Write an SQL query to find the users who have valid emails.

A valid e-mail has a prefix name and a domain where:

  • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter.
  • The domain is '@leetcode.com'.

Return the result table in any order.

The query result format is in the following example.




Fully-Explained Solution :

To write SQL query for selecting all rows from the Users table where the mail column to match with a regular expression pattern that describes a valid email address with has the domain @leetcode.com.

REGEXP :- It is the sequence of characters that specifies a match pattern in text

Approach :-

The regular expression pattern  should contain'^[a-zA-Z][a-zA-Z0-9._-]*@leetcode\\.com'

  1. ^ : specifies the starting charater of string
  2. [a-zA-Z]: matches only one upper or lower case letter in this sequence.
  3. [a-zA-Z0-9._-]*: matches zero or more letter of upper or lower case letter, digit, underscore, period, or dash.
  4. @leetcode\\.com: matches the string @leetcode.com, where the backslash is used to escape the period character.

Finally, This SQL query returns all rows from the Users table

  1. the mail column starts with a letter ^[a-zA-Z],
  2. followed by zero or more occurrences of letters, digits, underscores, periods, or dashes, [a-zA-Z0-9._-]*
  3. ends with @leetcode.com , '@leetcode\.com'

This satisfies the condition of a valid email address

SQL Query :-

SELECT *
FROM Users
WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9._-]*@leetcode\\.com' ;

Comments

Popular posts from this blog

1050. Actors and Directors Who Cooperated At Least Three Times || Leetcode sql solution || Simple and Easy Approach || ✅✅✅✅💯💯💯🔥🔥🔥🔥

Power of Millets || Happy And Healthy Life

AI in Daily Life