Reputation: 2800
I am trying to create regex to read the following statement
Finding all possible schedules that could run at Thu Jul 02 09:30:00 EST 2015 on monitor AAA-AAA_NameOf Place
.
Done So far::
string name = @"^Finding all possible schedules that could run
?<Listname>(\w{3}\-\w{3}\_)+"; //got kinda lost here
Regex reg = new Regex(name);
What do I want?
I want to get this AAA-AAA_NameOf Place
as an output and assign it in an list. As well as the date in the statement can be different every time.
Upvotes: 1
Views: 1251
Reputation: 39122
Here's a Regex that looks for a character at the beginning of a word boundary that is repeated three times then followed by a dash, then that same character repeated three more times followed by an underscore, then followed by any number of characters after that at the end of the string:
string input = "Finding all possible schedules that could run at Thu Jul 02 09:30:00 EST 2015 on monitor AAA-AAA_NameOf Place";
string pattern = @"\b(.)\1\1-\1\1\1_.+\Z";
Match m = Regex.Match(input, pattern);
if (m.Success)
{
Console.WriteLine(m.Value);
}
Upvotes: 1
Reputation: 11233
You can try this regex:
(.+? at )(?<Date>.+?)( on monitor )(?<NameOfPlace>.+)
It will product two named groups: Date
and NameOfPlace
.
Please note that it assumes the exactly same format.
Once you get the Date
and NameOfPlace
, you can assign them to List.
For how to get the values from regex matches.
Upvotes: 1
Reputation: 2141
Here you are:
var data = "Finding all possible schedules that could run at Thu Jul 02 09:30:00 EST 2015 on monitor AAA-AAA_NameOf Place";
string namePattern = @"(?<=monitor\s).*$";
Console.WriteLine(Regex.Match(data, namePattern).Value);
Refer here: https://msdn.microsoft.com/en-us/library/bs2twtah(v=vs.110).aspx#zerowidth_positive_lookahead_assertion
Hope this help.
Upvotes: 2