Find Regular Expression In String

Find all matches of a Regular Expression in a String.

Javadoc available at https://www.javatapas.com/docs/javatapas/string/FindRegularExpressionInString.html


public static void findRegularExpressionInString(String inStr, String regex) {

  	Pattern pattern = Pattern.compile(regex);
  	Matcher matcher = pattern.matcher(inStr);

   	boolean found = false;
   	while (matcher.find()){
  		System.out.println("Found the text \"" + matcher.group() + "\" starting at index " + matcher.start() + " and ending at index " + matcher.end() + ".");
  		found = true;
  	}
  	if (!found){System.out.println("No match found.");}

}