-1

I am trying to use regex to parse a string and extract the required data. Here's my string:

Validate control value for ELEMENT - VerifyFirstRowSearchNotes as ~Creating Stat Reserve: ~IP: Claimant Driver; IP Role(s): Owner, Driver~Exposure

I am trying to capture the data using the below regex pattern. I am interested in the data that follows "as" in particular. However, I am only able to capture control value below and not able to extract anything after "as" and assign it to fields group:

string actionpattern = @"Validate control value for ELEMENT - (?<control>.*?)as (?<fields>.*?)";
var regex = new Regex(actionpattern, RegexOptions.IgnoreCase);
var match = regex.Match({above string});

Let me know what I have been doing wrong. I am new to regex and in the process of learning.

Bendram
  • 120
  • 1
  • 9

1 Answers1

1

If you remove the question mark in this part (?<fields>.*?) you will make it greedy and match everything after as (?<fields>.*)

Your regex would look like:

Validate control value for ELEMENT - (?<control>.*?)as (?<fields>.*)

The fourth bird
  • 154,723
  • 16
  • 55
  • 70