Regex to split a string
Hi Guys,
I am currently working on ripping some information from a text file. I am trying to use regex to split up some strings.
I.e. text file has this line
Serial Number .............................. ABC123456AB
I need to just get the "ABC123456AB" part. So far I have not been able to work out the regex for it. I would like to search for " Serial Number .............................. " and return just the AB123456AB part.
Cheers
Wilson
[506 byte] By [
Cwilson] at [2007-12-23]
Following code snippet may help:
private void btnRegExTest_Click(object sender, System.EventArgs e)
{
Regex matcher
= new Regex(@"[^Serial][^Number]\s\w*",
RegexOptions.Multiline | RegexOptions.Compiled);
string str2Match
= "Serial Number .............................. ABC123456AB";
MatchCollection matches = matcher.Matches(str2Match);
if (matches != null && matches.Count > 0)
{
foreach (Match match in matches)
{
MessageBox.Show(match.ToString().Replace(".", string.Empty).Trim());
}
}
else
{
MessageBox.Show("No match found");
}
}
Cheers