JavaScript Methods of RegExp and String

2021

In this article we’ll cover various methods that work with regexps in-depth. 1. str.match(regexp) The method str.match(regexp) finds matches for regexp in the string str. It has 3 modes: If […]

JavaScript Sticky flag “y”, searching at position

2021

The flag y allows to perform the search at the given position in the source string. To grasp the use case of y flag, and better understand the ways […]

JavaScript Catastrophic backtracking

2021

Some regular expressions are looking simple, but can execute a veeeeeery long time, and even “hang” the JavaScript engine. Sooner or later most developers occasionally […]

2021

Sometimes we need to find only those matches for a pattern that are followed or preceded by another pattern. There’s a special syntax for that, […]

JavaScript Alternation (OR) |

2021

1. Overview Alternation is the term in regular expression that is actually a simple “OR”. In a regular expression it is denoted with a vertical […]

JavaScript Backreferences in pattern: \N and \k

2021

We can use the contents of capturing groups (…) not only in the result or in the replacement string, but also in the pattern itself. 1. Backreference […]

JavaScript Capturing groups

2021

A part of a pattern can be enclosed in parentheses (…). This is called a “capturing group”. That has two effects: It allows to get a […]

JavaScript Greedy and lazy quantifiers

2021

1. Overview Quantifiers are very simple from the first sight, but in fact they can be tricky. We should understand how the search works very […]

JavaScript Quantifiers +, *, ? and {n}

2021

Let’s say we have a string like +7(903)-123-45-67 and want to find all numbers in it. But unlike before, we are interested not in single digits, but […]

JavaScript Sets and ranges […]

2021

everal characters or character classes inside square brackets […] mean to “search for any character among given”. 1. Sets For instance, [eao] means any of the 3 characters: ‘a’, ‘e’, or ‘o’. […]

JavaScript Escaping, special characters

2021

As we’ve seen, a backslash \ is used to denote character classes, e.g. \d. So it’s a special character in regexps (just like in regular strings). There are […]

2021

2021

The multiline mode is enabled by the flag m. It only affects the behavior of ^ and $. In the multiline mode they match not only at the beginning […] JavaScript Anchors: string start ^ and end$

2021

1. Overview The caret ^ and dollar \$ characters have special meaning in a regexp. They are called “anchors”. The caret ^ matches at the beginning of the text, and the […]

JavaScript Unicode: flag “u” and class \p{…}

2021

1. Overview JavaScript uses Unicode encoding for strings. Most characters are encoded with 2 bytes, but that allows to represent at most 65536 characters. That range is […]

JavaScript Character classes

2021

1. Overview Consider a practical task – we have a phone number like “+7(903)-123-45-67”, and we need to turn it into pure numbers: 79031234567. To do so, […]

JavaScript Patterns and flags

2021

Regular expressions are patterns that provide a powerful way to search and replace in text. In JavaScript, they are available via the RegExp object, as well as […]

2021

1. Overview The idea behind shadow tree is to encapsulate internal implementation details of a component. Let’s say, a click event happens inside a shadow […]