A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://eslint.org/docs/rules/no-regex-spaces.html below:

no-regex-spaces - ESLint - Pluggable JavaScript Linter

no-regex-spaces

Disallow multiple spaces in regular expressions

Recommended

Using the recommended config from @eslint/js in a configuration file enables this rule

🔧 Fixable

Some problems reported by this rule are automatically fixable by the --fix command line option

Table of Contents

Regular expressions can be very complex and difficult to understand, which is why it’s important to keep them as simple as possible in order to avoid mistakes. One of the more error-prone things you can do with a regular expression is to use more than one space, such as:

In this regular expression, it’s very hard to tell how many spaces are intended to be matched. It’s better to use only one space and then specify how many spaces are expected, such as:

const re = /foo {3}bar/;

1

Now it is very clear that three spaces are expected to be matched.

Rule Details

This rule disallows multiple spaces in regular expression literals.

Examples of incorrect code for this rule:

Examples of correct code for this rule:

When Not To Use It

If you want to allow multiple spaces in a regular expression, then you can safely turn this rule off.

Version

This rule was introduced in ESLint v0.4.0.

Resources

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4