开发者

c# Regex for getting strings and number ranges

开发者 https://www.devze.com 2023-03-28 03:50 出处:网络
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

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

精彩评论

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