Validation methods for regular expressions

Validation of regular expressions:

1. Use Pattern to precompile strings

2. The object that calls the Matcher

3. Use the matches method of the Matcher object to return the value of boolean type (true if matched, false if not matched)

 

                String str = "123abcd";

		String exg= "^//d$";//Determine whether it conforms to the numeric type

		Pattern p = Pattern.compile(exg);//Complete the precompiled regular

		Matcher m = p.matcher(str);//To match the string

		boolean matches = m.matches();//Return matching results
		
		
                //Abbreviated as follows
		boolean m1 = Pattern.compile(str).matcher(a).matches();

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325077619&siteId=291194637