JAVA 正則表達式涉及的三個類:
String
Pattern是要匹配的模式
例如:Pattern p = plie(
Matcher m = p
要想在正則表達式中匹配一個反斜線用四個反斜線表示:
匹配空白行
找出匹配結果在整個字符串的開始位置和結束位置
Pattern p = plie(
String a =
Matcher m = p
m
m
while(m
{
System
}
將匹配到的java都轉換成大寫的
Pattern p = plie(
Matcher m = p
m
將匹配偶數個轉換為大寫
package zx
import java
import java
public class TestPattern
{
public static void main(String[] args)
{
StringBuffer newString = new StringBuffer();
String isPatternString =
Pattern p = pile(
Matcher m = p
int i =
while(m
{
i++;
if (i %
{
m
}
else
{
m
}
}
m
System
}
}
輸出結果:JAVA java JAVA Ilovejava You HateJAVA
Java正則表達式分組:
private static void testGroup()
{
String s =
Pattern p = pile(
Matcher m = p
while(m
{
System
}
}
輸出結果:
Group
Group
Group
Group
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26661.html