2012-07-19 136 views
1

之間我有一個很長的字符串正則表達式匹配字符串分隔符類似

等等等等等等 ** 一些文本1個嗒嗒 ** 更多等等... ** 一些文本2等等 ** 嗒嗒的Bleh ...

我想提取的字符串「**」所以我會得到

Some text 1 blah

Some text 2 blah

我試着使用:

var expression = @"(?<=**)(.*?)(?=**)"; 
var matches = Regex.Matches(theLargeString, expression); 

但它拋出一個錯誤:

parsing "(?<=**)(.*?)(?=**)" - Quantifier {x,y} following nothing. 

我是新來的正則表達式...任何建議?

+0

請相關的語言標記添加到您的問題 – Bohemian 2012-07-20 00:41:33

回答

1

你需要躲避* S ...

\*\*(.*?)\*\* 

正則表達式樣品1 enter image description here

+0

因爲您的數據看起來相當明確的界定,我覺得這避免「lookaround」的回答更簡單和更快,因此是優選的。 – sweaver2112 2012-07-20 00:46:09

相關問題