2013-04-26 111 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));