开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜