1 2 3 4 5 6 | String text = "This is the text to be searched " + "for occurrences of the http:// pattern."; String pattern = ".*http://.*"; boolean matches = Pattern.matches(pattern, text); System.out.println("matches = " + matches); |
1 2 3 4 5 6 | String text = "This is the text to be searched " + "for occurrences of the pattern."; String pattern = ".*is.*"; boolean matches = Pattern.matches(pattern, text); System.out.println("matches = " + matches); |
1 2 3 4 5 | String text = "This is the text to be searched " + "for occurrences of the http:// pattern."; String patternString = ".*http://.*"; Pattern pattern = Pattern.compile(patternString); |
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); |
Matcher matcher = pattern.matcher(text); |
1 2 3 4 5 6 7 8 | String text = "This is the text to be searched " + "for occurrences of the http:// pattern."; String patternString = ".*http://.*"; Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); boolean matches = matcher.matches(); System.out.println("matches = " + matches); |
1 2 3 4 5 6 7 8 | String text = "A sep Text sep With sep Many sep Separators"; String patternString = "sep"; Pattern pattern = Pattern.compile(patternString); String[] split = pattern.split(text); System.out.println("split.length = " + split.length); for(String element : split){ System.out.println("element = " + element); } |
1 2 3 | String patternString = "sep"; Pattern pattern = Pattern.compile(patternString); String pattern2 = pattern.pattern(); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |