Reputation: 1995
I have the following string (in vb.net):
Dim data as String = "-- Compiled: Aug 6 2015 10:07:08 --\nanotherline--\n..."
I'd like the output of regex.match() to look like the following:
Aug 6 2015 10:07:08
I'm trying variations of this:
Regex.Match(data, "(?<=Compiled:\s)(.*)(?<!-)", RegexOptions.IgnoreCase).ToString
but the best I can output is:
Aug 6 2015 10:07:08 --\nanotherline--\n...
How do I get regex to acknowledge the hyphen ("dash") character to stop matching?
Thank you in advance!
Upvotes: 1
Views: 75
Reputation: 785721
You don't to need to use lookbehind at RHS, just use negation
pattern:
Regex.Match(data, "(?<=Compiled:\s)([^-]*)\s-)", RegexOptions.IgnoreCase).ToString
Upvotes: 1
Reputation: 67988
(?<=Compiled:\s)(.*?)(?=-{2})
Use a lookahead
instead.See demo.
https://regex101.com/r/eX9gK2/9
Upvotes: 1
Reputation: 174806
You need to use positive lookahead with a non-greedy regex.
Regex.Match(data, "(?<=Compiled:\s).*?(?=\s*-)", RegexOptions.IgnoreCase).ToString
Upvotes: 2