Community Patterns

Community Library Entry

0

Regular Expression
Created·2023-07-13 03:14
Flavor·ECMAScript (JavaScript)

/
^(\d+)([" "])\1\2\1$
/
gmi
Open regex in editor

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