repeating multiple characters regex

前端 未结 5 447
春和景丽
春和景丽 2020-12-05 07:19

Is there a way using a regex to match a repeating set of characters? For example:

ABCABCABCABCABC

ABC{5}

I know that\'s wro

5条回答
  •  無奈伤痛
    2020-12-05 08:08

    ABC{5} matches ABCCCCC. To match 5 ABC's, you should use (ABC){5}. Parentheses are used to group a set of characters. You can also set an interval for occurrences like (ABC){3,5} which matches ABCABCABC, ABCABCABCABC, and ABCABCABCABCABC.

    (ABC){1,} means 1 or more repetition which is exactly the same as (ABC)+.

    (ABC){0,} means 0 or more repetition which is exactly the same as (ABC)*.

提交回复
热议问题