Home > Web Front-end > JS Tutorial > JavaScript Regex Cheat Sheet

JavaScript Regex Cheat Sheet

Lisa Kudrow
Release: 2025-03-17 10:44:11
Original
999 people have browsed it

JavaScript Regex Cheat Sheet

Proficient in using regular expressions requires understanding the purpose of each special character, flag, and method. This quick lookup table summarizes the usage of JavaScript regular expressions, which is convenient for you to check at any time.

Create regular expressions in JavaScript

 var regex = new RegExp('\u{61}', 'u');
console.log(regex.unicode); // true
Copy after login

The sticky search lastIndex property indicates the starting position of the search.

[Back to top]

Parentheses in regular expressions

Brackets are used for grouping. Sub-patterns can be formed using match() and replace() methods.

split() method

The split() method allows you to split the main string into substrings based on the delimiter specified as a regular expression.

 var texta = 'This 593 string will be broken294en at places where d1gits are.';
var regexone = /\d /g

// Output: ["This", " string will be broken", "en at places where d", "gits are."]
console.log(texta.split(regexone))
Copy after login

[Back to top]

Summarize

Previous tutorials have covered the basics of regular expressions, as well as some more complex expressions that can be very useful occasionally. These two tutorials explain how different characters or sequences of characters work in regular expressions.

The above is the detailed content of JavaScript Regex Cheat Sheet. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template