2013-04-26 116 views
0

我需要的多串的正则表达式如下需要一个正则表达式匹配多行字符串

Customer: 
      VA000347 
      VA000347 
      Ashu Corp 
      Others 
      Enterprise 

       Mumbai 
       5 
       Mumbai 
       Maharashtra 
       232323 
       India 

     :customer 

我想在Java中使用正则表达式来提取后期即从多行字符串“客户”和我可以从字面上匹配第一部分(客户)。

任何帮助,非常感谢。

+1

具有看看这个 http://stackoverflow.com/questions/5421952/how-to-match-multiple-words-in-regex – Mayur 2013-04-26 05:39:42

+0

这并不能真正帮助 – user1356042 2013-04-26 05:53:59

+2

又该输出在你的例子?只是这个词:顾客? – CloudyMarble 2013-04-26 06:59:17

回答

0
String text = "Customer:\n" 
      + "   VA000347\n" 
      + "   VA000347\n" 
      + "   Ashu Corp\n" 
      + "   Others\n" 
      + "   Enterprise\n" 
      + "\n" 
      + "    Mumbai\n" 
      + "    5\n" 
      + "    Mumbai\n" 
      + "    Maharashtra\n" 
      + "    232323\n" 
      + "    India\n" 
      + "\n" 
      + "  :customer"; 
    Pattern pattern = Pattern.compile("(?<=Customer:\n)(?s)(.*)(?=:customer)"); 
    Matcher matcher = pattern.matcher(text); 
    matcher.find(); 
    System.out.println(matcher.group(1));