Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String line = "John,Smith,123 Main St,Lake City,AB,37221,john.smith@gmail.com,";
- Pattern ptn = Pattern.compile("(^[A-Za-z0-9.'_%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$)",Pattern.CASE_INSENSITIVE);
- Matcher mtch = ptn.matcher(line);
- String newLine = mtch.replaceFirst("abc@gmail.com");
- assertEquals("John,Smith,123 Main St,Lake City,AB,37221,abc@gmail.com,", newLine);
- s.replaceFirst("[A-Za-z0-9.'_%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", "abc@gmail.com")
- ^ ^^ ^
- s.replaceFirst("[\w.'%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", "abc@gmail.com")
Add Comment
Please, Sign In to add comment