
JavaScript Methods of RegExp and String
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 […]
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 […]
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 […]
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 […]
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, […]
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 […]
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 […]
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 […]
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 […]
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 […]
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’. […]
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 […]
A word boundary \b is a test, just like ^ and $. When the regexp engine (program module that implements searching for regexps) comes across \b, it checks that the position […]
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 […]
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 […]
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 […]
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, […]
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 […]
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 […]
Shadow DOM may include both <style> and <link rel=”stylesheet” href=”…”> tags. In the latter case, stylesheets are HTTP-cached, so they are not redownloaded for multiple components that use same […]
1. Overview Many types of components, such as tabs, menus, image galleries, and so on, need the content to render. Just like built-in browser <select> expects <option> items, our <custom-tabs> may […]