c# - Regular expression question: Until next match OR End Of Document -


i'm working on document parser extract data documents i've been given , i'm coding in c#. documents in form:

 (type 1): (potentially multi-lined string) (type 2): (potentially multi-lined string) (type 3): (potentially multi-lined string) ... (type n): (potentially multi-lined string) (type 1): (potentially multi-lined string) ... end of document. 

the document repeats (type 1)-(type n) m times in same format

i'm having trouble multi-lined strings , finding last iteration of (type 1)-(type n)

what need capture (potentially multi-lined string) in group named preceeding (type #)

here snippet of document i'm trying match:

 name: john dow position: vp. on development bio: here long string of un important stuff include words "bio" or "name".  times have problems here, part should normal bio information position history: vp. on development sr. project manager jr. project manager developer peon notes: here notes may or may not multilined , if is, lines need captured person. name: joe noob position: peon bio: i'm peon, have little bio position history: peon notes: few notes name: jane smith position: vp. on sales bio: here long string of more un important stuff include words "bio" or "name".  times have problems here, part should normal bio information position history: vp. on sales sales manager secretary notes: here notes may or may not multilined , if is, lines need captured person. 



order of (type #) same , they're preceeded newline.

have:

 name:\s(?:(?.*?)\r\n)+?position:\s(?:(?.*?)\r\n)+?bio:\s(?:(?.*?)\r\n)+?position history:\s(?:(?.*?)\r\n)+?notes:\s(?:(?.*?)\r\n)+? 



great!

the simplest fix match in right-to-left mode:

regex r = new regex(@"name:\s(?:(.*?)\r\n)+?" +                     @"position:\s(?:(.*?)\r\n)+?" +                     @"bio:\s(?:(.*?)\r\n)+?" +                     @"position history:\s(?:(.*?)\r\n)+?" +                     @"notes:\s(?:(.*?)\r\n)+?",                     regexoptions.singleline | regexoptions.righttoleft); 

by way, had delete bunch of inappropriate question marks make work @ all. did want groups capture, didn't you?


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -