1.變數va與正則表示式abc*是否符合
if (va.matches("abc*")) {...}
2.正則表示式也可以放入變數內
String s="abc"
if (va.matches(s + "*")) {...}
3.也可以用compile的方式
其中group(0)代表全部匹配的內容,
group(1)代表第一個括號內的內容,
group(2)代表第二個括號內的內容, 以此類推
Pattern p = Pattern.compile("^\\\"(.+)\\\"$");
Matcher m = p.matcher(str);
if (m.find()) {
//group(1)是(.+)的內容
str = m.group(1);
//groupCount()表示整個表示式有三個括號的資料
if (matcher.groupCount() == 3) {
}
4.
//不區分大小寫
cStr ="\\w+";
Pattern pattern = Pattern.compile(cStr, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(contentString);
//如果contentString有多個符合結果, 可用while迴圈逐一取出來
while (matcher.find()) {
//matcher.start是匹配文字在整個字串中的開始位置
//matcher.end是匹配文字在整個字串中的結束位置
determinePos(matcher.start(), matcher.end(),
contentString.length());
}