Makes
the characters ^ and $ match the beginning and end of any line, as
opposed to the beginning and end of the entire input text.
import java.util.regex.*; public class RegExHarness { static Pattern pattern = Pattern.compile("^india.*", Pattern.MULTILINE); static Matcher matcher; public static void main(String[] args) { String data = "india is a good country\n" + "india is big country\n" + "india "; RegExHarness obj = new RegExHarness(); matcher = pattern.matcher(data); while (matcher.find()) { System.out.println(matcher.group()); } } }
Output
india is a good country india is big country india
No comments:
Post a Comment