cefeg
cefeg

Reputation: 33

.Net regex - extract data from one of two groups

Given two groups of data below and the limitation of .Net regex, no subtitution and no programmatic means, how can I capture data (Last Name or First Name) from the User Information group but not the Invoice Information group? When I construct a regex two results always occur.

User Information:
Title:                Product Specialist
Last Name:            Smithson
First Name:           Robert
Invoice Information: 
Title:                Buyer
Last Name:            Moneypenny
First Name:           Penelope

I can easily extract data from the Invoice group with this expression: (?<=Invoice\sInformation\:(.*\r\n)*Last\sName\:\s*).*, but the problem is the first group.

Upvotes: 1

Views: 68

Answers (1)

Derreck Dean
Derreck Dean

Reputation: 3766

Not sure if this will work for you as it references the "invoice" section as a marker to know where to stop collecting for the first name field, and therefore expects that the invoice section follows the user section. I'm assuming you want to extract all of the information and not just that one field:

User Information:\s+Title:\s+(.*?)\s+Last Name:\s+(.*?)\s+First Name:\s+(.*?)\s+Invoice

Upvotes: 0

Related Questions