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以上之前乱答一通请见谅,嘿嘿

解决方案 »

  1.   

    坐起来都写错,看来真是太晚了output是$java regexTest
    you'd
    Students'
    The-state-art
    Auto-generated
      

  2.   

    \\w+(('|-)\\w*)这可以匹配任意长度以‘或-分割的\\w字符串如果要改变分割符,只要把(’|-)括号里面的换成别的分割符就行了
      

  3.   

    另外你在原贴中提到的提取英文缩写的正则表达式如下和第一题很相似 
    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