Regular Expressions 101

Community Patterns

1...456

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^(\d+)([" "])\1\2\1$
/
gmi

Description

resolving the free code camp reuse-patterns-using-capture-groups problem

    let repeatNum = "42 42 42";
    let reRegex = /^(\d+)([" "])\1\2\1$/;

^ starts with (\d+) a digit with at least one char (or else will count spaces) and have a([" "])(space) after the digit and \1 to repeat the digit \2to repeat the space \1 to repeat the digit regex again and $ to garan it will stop after encountering a char different than the digit.

Submitted by gabriel silva lima - a year ago