Hi there,
Regex is one of those things that takes some time to get used to. If I
read your question right, you want to find a line that looks like
<beginning of line><some set of digits><the word "ERRORS">
If that's what you want, take a look at this code:
string stringToSearch = "Don't match this line" + Environment.NewLine
+ "Or this line" + Environment.NewLine + "25 ERRORS";
string patternToMatch = "^[0-9]+ ERRORS";
Regex reg1 = new Regex(patternToMatch,RegexOptions.Multiline);
Match m = reg1.Match(stringToSearch);
if (m.Success)
MessageBox.Show(m.Value);
The Regex in this case breaks down like this:
^ means match the beginning of a line
[0-9]+ means match any number of digits
ERRORS means just match the string
Hope that helps,
John
..... wrote:
Hi
I'm trying to do something which I think is pretty simple, but really I
don't know what I'm doing :-)
I have a string like this
HELLO WORLD
25 ERRORS
I want to search the string and return and line with the word ERRORS
25 ERRORS
I've tried this, but it's not working... Can oneone help a dummy please?
Thanks
Regex reg1 = new Regex("HELLO WORLD" + Environment.NewLine + "25 ERRORS");
Match m;
m = reg1.Match(".ERRORS.");
textBox2.Text = m.Value;