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

前端 未结 15 2231
北荒
北荒 2020-11-28 11:41

I need regular expressions to match the below cases.

  1. 3 or more consecutive sequential characters/numbers; e.g. 123, abc, 789, pqr, etc.
  2. 3 or more cons
15条回答
  •  抹茶落季
    2020-11-28 12:34

    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).

提交回复
热议问题