rickyProgrammer
rickyProgrammer

Reputation: 1167

Regular expression to match multiple set of string patterns using C# in ASP.Net

I currently have a code in C# that counts for the occurrence of a single pattern

  MatchCollection collection = Regex.Matches(readedLine, @"work=R");
  countedChars = collection.Count;

What to do when I need to find or match a multiple set of string or pattern in a line. For example

if "work=R", "product=X" and "function=V" are all found in one line, then it will have 1 count automatically, otherwise, or if one of them does not match, it will not be counted.

Upvotes: 0

Views: 381

Answers (1)

Andrew Arace
Andrew Arace

Reputation: 457

You want a lookahead, and probably with start and end line markers.

Here's an example: http://regexr.com/3f8pk

Otherwise, if you don't have to process a LOT of data, you can have three separate regex patterns, and see if your line matches all three.

Upvotes: 1

Related Questions