ebattulga
ebattulga

Reputation: 10981

how to split this line using regular expression in c#

Input

-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]

I need to split this like this
-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]

My Expression is here ((—\w\.)|(\d\s))(([^\d—])*)

But this fails on card1]

How to solve this?

How to negate digit followed with space?

Upvotes: 0

Views: 124

Answers (2)

Tanzelax
Tanzelax

Reputation: 5714

Utilize lookahead:

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

You want any number of non-digits or non-dashes ([^\d-]), but you also want to allow digits that aren't followed by spaces (\d(?!\s)) and hyphens that aren't followed by characters and periods (-(?!\w\.)).

Upvotes: 3

Renana Yacobi
Renana Yacobi

Reputation: 86

You should do Regex.Escape to your input string.

Upvotes: -1

Related Questions