Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static int[] getIndex(String text, String regex) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(text); int[] data = new int[2]; // Check all occurrences while (matcher.find()) { data[0] = matcher.start(); data[1] = matcher.end(); // System.out.print("Start index: " + matcher.start()); // System.out.print(" End index: " + matcher.end()); // System.out.println(" Found: " + matcher.group()); } return data; } }