java - 正则

match

1
2
3
4
5
6
7
8
9
10
11
12
13
// string.match: yes OR no
private static final String REGEX = "^@encrypt\\{(.*)}$";
"@encrypt{file:mysql.username}".match(REGEX); // return true

// Pattern
String REGEX = "^@encrypt\\{(.*)}$";
Pattern PT = Pattern.compile(REGEX);
Matcher m = PT.matcher(value);

m.find(); // find matched subsequence one by one; yes OR no
m.match(); // match entire string; yes OR no

// group