Is there a regex (or any other way) to check if a numbers in a string is in running sequence?
E.g.,
"123456" will return true
"456789" will return true
"345678" will return true
"123467" will return false
"901234" will return false
If all your sequences are composed of single-digit numbers, then you can solve this by observing that all correct sequences must be substrings of the longest such sequence, i.e. of "0123456789"
. So the check can be done like this:
bool res = "0123456789".Contains(str);
Demo on ideone.
How about this:
text.Skip(1).Zip(text, (c1, c0) => new { c1, c0 }).All(c => c.c1 - c.c0 == 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With