package com.xx; import java.util.Arrays; import java.util.regex.Matcher; import
java.util.regex.Pattern; /** * Pattern&Matcher * * @author xx * */ public class
Test1 { public static void main(String[] args) { // Create a regular expression Pattern pattern =
Pattern.compile("[0-9]+"); System.out.println(" regular expression :" + pattern); // Use regular match strings
boolean matches = Pattern.matches("[0-9]+", "abcde123");
System.out.println(" Match regular expression or not :" + matches); // Using regular expressions to cut strings String[] arr =
pattern.split("a1b2c3d4"); Arrays.stream(arr).forEach(System.out::println); //
Matcher Provide more powerful regular matching operations Matcher matcher = pattern.matcher("a1b2c3d4"); // Match all strings
boolean matches2 = matcher.matches(); System.out.println(" Match regular expression or not :" +
matches2); // Match only the first string boolean lookingAt = matcher.lookingAt();
System.out.println(" Does the initial match the regular expression :" + lookingAt); // Is there a match ( be similar to contains)
boolean find = matcher.find(); System.out.println(" Is there a match :" + find); Pattern
pattern2 = Pattern.compile("[0-9]+"); Matcher matcher2 =
pattern2.matcher("aaa2223bb4444"); // Match filtered strings , Default back to first matcher2.find(); //
View the results of the last match String string = matcher2.toString(); System.out.println("string" +
string); // Match first filtered substring // matcher2.lookingAt(); // Match entire string //
matcher2.matches(); // Returns the index location of the first match , Default back to first int start = matcher2.start(); //
Returns the index location of the last match , Default back to first int end = matcher2.end(); // Returns the matching string String group =
matcher2.group(); System.out.println(start); System.out.println(end);//
Here is 7 Because 2223 As a whole System.out.println(group); // eg Pattern pattern3 =
Pattern.compile("[a-z]+"); Matcher matcher3 =
pattern3.matcher("aaa111bbb222ccc333"); while (matcher3.find()) {
System.out.println(" Filter results :" + matcher3.group() + "; Substring subscript :" + matcher3.start());
} } }
 

Technology
©2019-2020 Toolsou All rights reserved,
centos lower zip Compression and decompression command TypeScript Data types in is enough 【Python- data fetch 】 read txt Each line of file generates a list of data el-select Get selected label value vue Value transfer between parent-child and non parent-child components 11-5 Output string at specified position fio Use details inherit jpa Repository Write custom method query Map---Java judge Map Contains a keykeras Data generator -- Data enhancement