Reputation: 175
I have a following pattern rather complex:
^(?=.*\b(?:averages?|standard|means?)\b)(?=.*\b(?:goods?)\b)(?=.*\b(?:costs|cost to the company|sold by vendors?|bought from vandors?)\b).*$
and its very nicely matching the following sentences:
What is average goods costs.
give me a standard list of goods bought from vendors.
list all standard goods sold by vendors.
I have to remove the matched pattern part from sentences i.e.
what is __ list of _______.
give me ________ for ______.
list all _____________.
I am trying to split the pattern and thinking of performing match for every split instance of the pattern but its daunting so looking for a alternative solution thanks.
I trying to get the following to work.
string[] splitPat = value.Split(new string[] { ")(" }, StringSplitOptions.None);
THANKS
Upvotes: 1
Views: 193
Reputation: 45135
Just put the pieces you want to be able to extract into groups by wrapping them in an extra set of ()
. For example:
^(?=.*\b((?:averages?|standard|means?))\b)(?=.*\b((?:goods?))\b)(?=.*\b((?:costs|cost to the company|sold by vendors?|bought from vandors?))\b).*$
When matching this string:
What is average goods costs.
average
, goods
and costs
become the first, second and third group in your match.
Try playing with it here:
http://rubular.com/r/urb1raJ3W7
You can try different test strings and see what groups it will extract.
Then in .NET you can use Match.Groups to access the groups in a match. You can even name the groups if you want for easier maintanence.
Upvotes: 1