http://topic.csdn.net/u/20100513/00/6fd9d903-e681-4291-bace-5c4be364830e.html?58546#replyachor
我刚才躺在床上回帖结果错误百出连续回复了三贴不让回复了,现更正如下
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class regexTest
{
public static void main(String [] args)
{
String S = "you'd better have a try . Students' name ssssss . The-state-art . Auto-generated method stub";
String regex = "\\w+(('|-)\\w*)+"
Pattern P = Pattern.compile(regex);
Matcher M = P.matcher(S);
while(m.find())
{
System.out.println(m.group());
}
}
}
output:
$java regexTest
you'd
The-state-art
Auto-generated以上之前乱答一通请见谅,嘿嘿
you'd
Students'
The-state-art
Auto-generated
String S = "K.G.B. U.S.A Washington D.C haha lalala youhou S.S";
Pattern P = Pattern.compile("\\w\\.(\\w\\.?)+");
Matcher M = P.matcher(S);while(m.find())
{
System.out.println(m.grouup());
}
output:K.G.B.
U.S.A
D.C
S.S