Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a Regex pattern for 3 consecutive digits increasing or decreasing

Tags:

regex

I need a regex pattern to match a sequence of 3 consecutive digits in a string that are consecutively increasing or decreasing.

For example:

These strings should match (xxx123xxx, 789xxxxxx, xxxxxx987, xxxxxx432)

These strings should not match (xxxxxx454, 333xxxxxx, xxx429xxx)

like image 209
user106776 Avatar asked Feb 02 '10 15:02

user106776


1 Answers

There is no other way than listing them:

(012|123|234|345|456|567|678|789|987|876|765|654|543|432|321|210)
like image 191
Gumbo Avatar answered Sep 29 '22 09:09

Gumbo