Answer the question
In order to leave comments, you need to log in
Whole line in c# regex?
Good afternoon, There is a lot of text divided line by line,
i.e. in each line a certain number of characters - then a break.
It is necessary that when a word is found, all lines where the given word exists are written to a buffer or variable, and anywhere.
var s = File.ReadAllText(textPath.Text);
Regex regex = new Regex(@"text", RegexOptions.IgnoreCase | RegexOptions.Multiline);
MatchCollection matches = regex.Matches(s);
if (matches.Count > 0)
{
foreach (Match match in matches)
{
// Write the string array to a new file named "WriteLines.txt".
using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(@"C:\", "mq.txt")))
{
outputFile.WriteLine(match);
}
}
}
Answer the question
In order to leave comments, you need to log in
(^.*text.*$)
^ - start of string
$ - end
.* - any number of any characters
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question