We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 28: RegEx, Patterns, and Intro to Databases
Day 28: RegEx, Patterns, and Intro to Databases
+ 0 comments Python 3 (No RegEx)
if __name__ == '__main__': N = int(input().strip()) names = [] for N_itr in range(N): first_multiple_input = input().rstrip().split() firstName = first_multiple_input[0] emailID = first_multiple_input[1].split('@') if emailID[1] == 'gmail.com': names.append(firstName) print(*sorted(names),sep="\n")
+ 0 comments swift Solution
let times = Int(readLine()!)! let transactionRegex = #"([a-z]{0,})\s[a-zA-Z.]{0,}@gmail.com"# var outputs = [String]() for _ in 1...times { let input = readLine()! do { let regex = try NSRegularExpression(pattern: transactionRegex, options: .caseInsensitive) let matches = regex.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count)) for match in matches { let range = match.range if let swiftRange = Range(range, in: input) { let name = input[swiftRange] outputs.append(String(name).components(separatedBy: .whitespaces)[0]) } } } catch { print("regex was bad!") } } let desired = outputs.sorted(by: <) for name in desired { print(name) }
+ 0 comments c# public static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine().Trim());
Regex regex = new Regex(@"[a-z]{1,20}"); Regex regex1 = new Regex(@"([a-z]{1,50}@gmail.com)"); List<string> list = new List<string>(); for (int NItr = 0; NItr < N; NItr++) { string[] firstMultipleInput = Console.ReadLine().TrimEnd().Split(' '); string firstName = firstMultipleInput[0]; string emailID = firstMultipleInput[1]; bool name = regex.IsMatch(firstName); bool email = regex1.IsMatch(emailID); if (name && email) { list.Add(firstName); } } list.Sort(); foreach (string item in list) { Console.WriteLine(item); } }
+ 0 comments import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(bufferedReader.readLine().trim()); String regex = "(?<gml>[\\w.]+@gmail.com)"; Pattern p = Pattern.compile(regex); Matcher m ; List<String> validUsers = new ArrayList(); IntStream.range(0, N).forEach(NItr -> { try { String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); String firstName = firstMultipleInput[0]; String emailID = firstMultipleInput[1]; if(emailID.matches(regex)) { validUsers.add(firstName); } } catch (IOException ex) { throw new RuntimeException(ex); } }); Collections.sort(validUsers); validUsers.stream().forEach((u) -> {System.out.println(u);}); bufferedReader.close(); } }
+ 0 comments #!/bin/python3 import math import os import random import re import sys if __name__ == '__main__': N = int(input().strip()) names=[] for N_itr in range(N): first_multiple_input = input().rstrip().split() firstName = first_multiple_input[0] emailID = first_multiple_input[1] # if emailID.endswith("@gmail.com"): if re.match(r'.*@gmail.com$', emailID): names.append(firstName) print(*sorted(names),sep="\n")
Load more conversations
Sort 599 Discussions, By:
Please Login in order to post a comment