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.
Detect the Email Addresses
Detect the Email Addresses
+ 0 comments import re pattern= re.compile(r'\b[\w.]+@[a-zA-Z0-9.]+\w\b') n=input() email=[] for i in range(eval(n)): text=input() add=pattern.findall(text) if add: email.extend(add) set_email=list(set(email)) set_email.sort() string=';'.join(set_email) print(string)
+ 0 comments regex_pattern=r"([\w.]*@[\w.]*\.[a-z]+)"
+ 0 comments Java 8
public static void findEmailAddresses(ArrayList<String> items) { Pattern pattern = Pattern.compile("\\w*\\.?[a-zA-Z_0-9]+@([a-zA-Z_0-9]+\\.)+[a-zA-Z_0-9]+"); HashMap<String, String> hashMap = new HashMap<String, String>(); for (String item : items) { Matcher matcher = pattern.matcher(item); while(matcher.find()) { String value = matcher.group(); hashMap.put(value, value); } } ArrayList<String> outputList = new ArrayList<String>(hashMap.keySet()) ; Collections.sort(outputList); String outputStr = ""; for (String item : outputList) { outputStr += item + ";"; } if (!outputStr.isEmpty()) outputStr = outputStr.substring(0, outputStr.length()-1); System.out.print(outputStr); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine(); ArrayList<String> sentenceArrayList = new ArrayList<String>(); while (scanner.hasNextLine()) { sentenceArrayList.add(scanner.nextLine()); } findEmailAddresses(sentenceArrayList); }
+ 0 comments Python 3
import re import sys test_string = sys.stdin.read() matches = re.findall(r'(\w*\.?\w+@(?:[a-z]+\.)+\w+)', test_string) print(';'.join(sorted(set(matches))))
+ 0 comments Python 3: two lines :-P
import re print(';'.join(sorted(set([i.group() for i in re.finditer(r'\w+(\.\w+)*@\w+(\.\w+)+',' '.join([input() for _ in range(int(input()))]))]))))
Load more conversations
Sort 164 Discussions, By:
Please Login in order to post a comment