I want to write a regular expression that will find instances of three or more consecutive letters of the alphabet. I'm planning to use this regex with both JavaScript and grep
. This seems like something that regex should be able to do pretty easily, but I'm having a hard time coming up with a regex that isn't very complicated:
(abc(d(e(f(g(h(i(j(k(l(m(n(o(p(q(r(s(t(u(v(w(x(yz?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)|(bcd(e(f(g(h(i(j(k(l(m(n(o(p(q(r(s(t(u(v(w(x(yz?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)|(cde(f(g(h(i(j(k(l(m(n(o(p(q(r(s(t(u(v(w(x(yz?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)|...
To be clear, I want to match these test cases:
abc
- matchabc
def
- matchdef
lmnop
- matchlmnop
xxxxghixxxx
- matchghi
ab
- no match (not long enough)zyx
- no match (not in order)q r s
- no match (interceding chararacters)tuwx
- no match (missingv
)
Is there a way to write this regex that doesn't use 20+ levels of nested parenthesis and 20+ |
s?