Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Created·2021-02-15 16:44
Flavor·PCRE2 (PHP)

/
function (?<name>[a-zA-Z0-9]+)\s*(?<arguments>\([^()]*\)(?::\s*[^{}\s]*)?)\s*(?<body>\{[^\r{}]*(?:\{[^\r{}]*(?:\{[^\r{}]*(?:\{[^\r{}]*(?:\{[^\r{}]*(?:\{[^\r{}]*\}[^\r{}]*)*\}[^\r{}]*)*\}[^\r{}]*)*\}[^\r{}]*)*\}[^\r{}]*)*\})(?:;)?
/
gm
Open regex in editor

Description

This regex takes a function declaration and transforms it to an arrow function.

Replace: const $1 = $2 => $3;

Submitted by anonymous