Regular Expressions 101

Community Library

Community Library Entry

0

Regular ExpressionOpen Workspace

/
^data-(test|cy|jest).*$
/
gm

Description
Created·2022-08-10 09:09
Type·Substitution
Flavor·PCRE (Legacy)

Match Test Properties

This regular expression is used on next.config.js and is used to remove test attributes from the production build.

It filters any data attributes that starts with 'test', 'cy' or 'jest'.

Match examples

Using 'test' data attributes

Inputs: SPAN 1 SPAN 2 SPAN 3

Outputs: SPAN 1 SPAN 2 SPAN 3

Using 'jest' data attributes

Inputs: SPAN 1 SPAN 2 SPAN 3

Outputs: SPAN 1 SPAN 2 SPAN 3

Using 'cy' data attributes

Inputs: SPAN 1 SPAN 2 SPAN 3

Outputs: SPAN 1 SPAN 2 SPAN 3

Usage

module.exports = {
  compiler: {
    // The regexes defined here are processed in Rust so the syntax is different from
    // JavaScript `RegExp`s. See https://docs.rs/regex.
    reactRemoveProperties: { properties: ['^data-(test|cy|jest).*$'] },
  },
}
Submitted by Patrick Fantato <patrick@madebyon.com>
Open Workspace