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

前端 未结 15 2280
北荒
北荒 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:24

    For case #2 I got inspired by a sample on regextester and created the following regex to match n identical digits (to check for both numbers and letters replace 0-9 with A-Za-z0-9):

    const n = 3
    const identicalAlphanumericRegEx = new RegExp("([0-9])" + "\\1".repeat(n - 1))
    

提交回复
热议问题