Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws ParseException {
- Pattern p = Pattern.compile("\d\d\d");
- Matcher m = p.matcher("a123b");
- System.out.println(m.find());
- System.out.println(m.matches());
- p = Pattern.compile("^\d\d\d$");
- m = p.matcher("123");
- System.out.println(m.find());
- System.out.println(m.matches());
- }
- /* output:
- true
- false
- true
- true
- */
- final Matcher subMatcher = Pattern.compile("\d+").matcher("skrf35kesruytfkwu4ty7sdfs");
- System.out.println("Found: " + subMatcher.matches());
- System.out.println("Found: " + subMatcher.find() + " - position " + subMatcher.start());
- System.out.println("Found: " + subMatcher.find() + " - position " + subMatcher.start());
- System.out.println("Found: " + subMatcher.find() + " - position " + subMatcher.start());
- System.out.println("Found: " + subMatcher.find());
- System.out.println("Found: " + subMatcher.find());
- System.out.println("Matched: " + subMatcher.matches());
- System.out.println("-----------");
- final Matcher fullMatcher = Pattern.compile("^\w+$").matcher("skrf35kesruytfkwu4ty7sdfs");
- System.out.println("Found: " + fullMatcher.find() + " - position " + fullMatcher.start());
- System.out.println("Found: " + fullMatcher.find());
- System.out.println("Found: " + fullMatcher.find());
- System.out.println("Matched: " + fullMatcher.matches());
- System.out.println("Matched: " + fullMatcher.matches());
- System.out.println("Matched: " + fullMatcher.matches());
- System.out.println("Matched: " + fullMatcher.matches());
- find()
- public static void main(String[] args) {
- Pattern p = Pattern.compile("\d");
- String candidate = "Java123";
- Matcher m = p.matcher(candidate);
- if (m != null){
- System.out.println(m.find());//true
- System.out.println(m.matches());//false
- }
- }
- 1:Pattern.compile("[a-z]");
- 2:Pattern.matcher("0a1b1c3d4");
- 3:int count = 0;
- 4:while(matcher.find()){
- 5:count++: }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement