如何在c#中使用正则表达式拆分此行

时间:2012-04-15 07:48:16

标签: c# regex

输入

-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

2 个答案:

答案 0 :(得分:3)

利用前瞻:

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

您需要任意数量的非数字或非破折号([^\d-]),但您还希望允许未跟空格(\d(?!\s))的数字和未跟随的连字符字符和句点(-(?!\w\.))

答案 1 :(得分:-1)

您应该对输入字符串Regex.Escape