2012-04-15 45 views
0

輸入如何在C#中使用正則表達式來拆分此行

-n. 1 geographical map or plan, esp. for navigation. 2 sheet of information in the form of a table, graph, or diagram. 3 (usu. in pl.) colloq. listing of the currently best-selling pop records. -v. make a chart of, map. [Latin charta: related to *card1]

我需要分割該這樣
-n.
1 geographical map or plan, esp. for navigation.
2 sheet of information in the form of a table, graph, or diagram.
3 (usu. in pl.) colloq. listing of the currently best-selling pop records.
-v.
make a chart of, map. [Latin charta: related to *card1]

我的表情是這裏 ((—\w\.)|(\d\s))(([^\d—])*)

但這未能對card1]

如何解決這個問題?

如何否定digit followed with space

回答

3

利用前瞻:

((-\w\.)|(\d\s))(([^\d-]|(\d(?!\s))|(-(?!\w\.)))*) 

你想要的任何數量的非數字或非破折號([^\d-]),但你也希望允許不跟空格(\d(?!\s))和連字符是不是活得位t之後是字符和句點(-(?!\w\.))

-1

你應該對你的輸入字符串做Regex.Escape

+1

這與這個問題有什麼關係?如果輸入應該用作正則表達式的一部分,並且整個用戶輸入必須與字面匹配,則「Regex.Escape」纔有意義。應該從字面上匹配']'。 – stema 2012-04-15 09:18:46