Regular Expression to match 3 or more Consecutive Sequential Characters and Consecutive Identical Characters

Solution 1:

I don't think you can use regex for the first case. The second case is easy though:

Pattern pattern = Pattern.compile("([a-z\\d])\\1\\1", Pattern.CASE_INSENSITIVE);

Since \\1 represents part matched by group 1 this will match any sequence of three identical characters that are either within the range a-z or are digits (\d).

Solution 2:

I disagree, case 1 is possible to regex, but you have to tell it the sequences to match... which is kind of long and boring:

/(abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)+/ig

http://regexr.com/3dqln