일부 코드정칙

2318 단어 StringClassimport
재미없어, 여기다 놔두고 쓸 때 한 번 봤을 뿐이야.
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Demo01
{
    public static void main(String[] args)
    {
	System.out.println("abc".matches("..."));
	System.out.println("a78432fdasf4321d".replaceAll("\\d", "-"));
	
	Pattern p = Pattern.compile("[a-z]{3}");//    ,      a-z
	Matcher matcher = p.matcher("dfd");
	System.out.println(matcher.matches());
	
	System.out.println("a".matches("."));
	System.out.println("aa".matches("a*"));
	System.out.println("aaa".matches("a+"));
	System.out.println("aaa".matches("a?"));
	System.out.println("".matches("a*"));
	System.out.println("".matches("a?"));
	System.out.println("a".matches("a?"));
	System.out.println("123345443234".matches("\\d{0,20}"));
	System.out.println("123345443234".matches("\\d{4}"));
	System.out.println("123345443234".matches("\\d{4,}"));
	System.out.println("192.178.34.123".matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"));
	System.out.println("192".matches("[0-2][0-9][0-9]"));
	
	System.out.println("a".matches("[abc]"));
	System.out.println("a".matches("[^abc]"));//  abc
	System.out.println("a".matches("[a-zA-Z]"));//a-z A-Z
	System.out.println("a".matches("[a-z] | [A-Z]"));//a-z A-Z
	System.out.println("a".matches("[a-z[A-Z]]"));//a-z A-Z
	System.out.println("R".matches("[A-Z&&[RFG]]"));// A-Z  ,   RFG  
	
	System.out.println(" 
\r\t".matches("\\s{4}")); System.out.println(" ".matches("\\S")); System.out.println("a_8".matches("\\w{3}")); System.out.println("abc888&^#%".matches("[a-z]{3}\\d+[&^#%]+")); System.out.println("\\".matches("\\\\"));// System.out.println("hello world".matches("^h.*")); System.out.println("hello world".matches(".*ld$")); System.out.println("hello world".matches("^h[a-z]{4}\\s[wor]{3}ld$")); } }

좋은 웹페이지 즐겨찾기