2011-03-17 56 views
0

我有型問題上正則表達式

"X-Request-Recipients: assignee:tammalac; cat:angub; cat:bashas; cat:bhattacs; sev:nukalas; sev:[email protected]; sub-all:majumdaa;sub-all:mayakunp; sub-all:srinivay; sub-all:tammalac; " 

的字符串現在質疑的是正則表達式表達後提取任意數量的字符串:和之前。

P.S.我會從perl腳本訪問這個。

+0

嗨Pradeep,我看不到上面的任何字符串示例。 – cordellcp3 2011-03-17 14:44:33

+0

你有你的字符串樣本的樣本嗎? – Duniyadnd 2011-03-17 14:44:41

+1

你已經試過了什麼?常數是什麼? (會不會有空格?它總是字母/數字等等)'\ w +:\ w +;'對我來說工作正常。 – 2011-03-17 14:46:08

回答

4

匹配這些部分將是作爲結果組1的

\w:([^;]+); 

,或者更具體

(?:username|subscriber):([^;]+); 

使用內容的正則表達式。

\w:  # a word character and a colon 
(  # begin group 1 
    [^;]+ # any character except a semi-colon, at least one 
)  # end group 1 
;  # a semi-colon 
+0

感謝這工作..欣賞你在這裏提供的清晰度。我如何繼續遍歷,直到到達結束的時候? – 2011-03-18 07:42:49

+1

忽略我的上一條評論。我自己找到了解決方案:) – 2011-03-18 08:57:42

1

試試這個正則表達式:

:([^;]+) 

使用您的示例文本,這將工作。