c# Regex for getting strings and number ranges
I want to tell whether o开发者_JAVA百科r not a string contains "x mins ago" or "Just Now" x being a number between 1 and 5.
n mins ago
/^\d+ mins ago$/
If you explicitly want only a number between 1 and 5...
/^[1-5] mins ago$/
Just Now
Just do a normal string comparison. No reason to use regex to match a constant string.
You can try this:
^([1-5] mins ago)|(Just Now)$
In C# you can try this:
Regex.IsMatch(yourString, @"([1-5]\s+mins\s+ago|just\s+now)", RegexOptions.IgnoreCase);
精彩评论