Guest User

Untitled

a guest
Oct 19th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. String line = "John,Smith,123 Main St,Lake City,AB,37221,john.smith@gmail.com,";
  2. Pattern ptn = Pattern.compile("(^[A-Za-z0-9.'_%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$)",Pattern.CASE_INSENSITIVE);
  3. Matcher mtch = ptn.matcher(line);
  4. String newLine = mtch.replaceFirst("abc@gmail.com");
  5. assertEquals("John,Smith,123 Main St,Lake City,AB,37221,abc@gmail.com,", newLine);
  6.  
  7. s.replaceFirst("[A-Za-z0-9.'_%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", "abc@gmail.com")
  8. ^ ^^ ^
  9.  
  10. s.replaceFirst("[\w.'%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", "abc@gmail.com")
Add Comment
Please, Sign In to add comment