Java tutorial
import java.util.regex.Pattern; import java.util.regex.Matcher; public class Main { public static void main(String[] args) { String regex = "[abc]@."; String source = "abc@example.com"; findPattern(regex, source); } public static void findPattern(String regex, String source) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(source); System.out.println("Regex:" + regex); System.out.println("Text:" + source); while (m.find()) { System.out.println("Matched Text:" + m.group() + ", Start:" + m.start() + ", " + "End:" + m.end()); } } }