Hi, I want to extract the status from the string untill I found a timespan. My input is something like "Something in start but not with this keyword of sure. STATUS: My Status Is Here Which can be anything but timespan 23:59:01 and so on. I want to extract the string after STATUS: untill 23:59:01 is found. How can i achieve this through regex. this 23:59:01 is a timespan and it is always in this format hh:mm:ss
+1
A:
Your specification is rather unclear, but you can try STATUS: (.*?) \d{2}:\d{2}:\d{2}
; this captures the portion that you want into group 1.
You may want to enable singleline if the .
is to also match newline.
See also
- Above regex in action on rubular.com
- (we can go back and forth on rubular if you need the pattern fine tuned further)
In C#, you'd write something like this (see it on ideone.com):
Regex r = new Regex(@"STATUS: (.*?) \d{2}:\d{2}:\d{2}", RegexOptions.Singleline);
foreach (Match match in r.Matches(text)) {
Console.WriteLine("[[[" + match.Groups[1] + "]]]");
}
The RegexOptions.Singleline
allows .
to match any character, so it works when the desired string contains newlines.
References
Why reluctant?
That's just in case you need multiple matches (as shown above). In the example below, there is only one A.*Z
(with greedy).
---A--Z----A----Z---
^^^^^^^^^^^^^^
A.*Z
polygenelubricants
2010-06-09 08:23:49
What language are you using? I am using .netpolygenelubricants I think you got what i want but your provided regex is not working. Another thing i want to add is my status can be on multiple line. To further clear my requirements. I need to extract any thing between STATUS: and \d{2}:\d{2}:\d{2}
ZafarYousafi
2010-06-09 09:08:51