Reputation: 5987
Im searching for a pattern within a file. This pattern is not limited to a single line. It spreads over more than one line, i.e. more than one line group together to contain this pattern. Hence, it's not possible to loop through line-by-line in the file and check whether the pattern exists or not. The pattern is given below:
/public.+\s+(\w+)\([^\)]*\)\s*.+?return\s*\w+?\.GetQuestion\s*\(/g
Can anyone please tell the C# coding how to match the pattern with in the file ?
Upvotes: 2
Views: 240
Reputation: 1500815
I suspect you need to read the whole file (using ReadToEnd
, as suggested by RandomNoob) but then also specify RegexOptions.Singleline
to put it into Singleline mode:
The RegexOptions.Singleline option, or the s inline option, causes the regular expression engine to treat the input string as if it consists of a single line. It does this by changing the behavior of the period (.) language element so that it matches every character, instead of matching every character except for the newline character \n or \u000A.
Regex pattern = new Regex(
@"public.+\s+(\w+)\([^\)]*\)\s*.+?return\s*\w+?\.GetQuestion\s*\(",
RegexOptions.Singleline);
Upvotes: 4