RegExp
Last updated
Last updated
RegExp.prototype.compile()
ЗАСТАРІЛЕ!
(Пере-) компілює регулярний вираз під час виконання сценарію.
Виконує пошук відповідності в параметрі рядка.
Перевіряє збіг у своєму рядковому параметрі.
Повертає рядок, що представляє вказаний об’єкт. Перевизначає Object.prototype.toString()
method.
Виконує зіставлення з заданим рядком і повертає результат збігу.
RegExp.prototype[@@matchAll]()
Повертає всі збіги регулярного виразу з рядком.
Замінює збіги в заданому рядку новим підрядком.
Шукає відповідність у заданому рядку та повертає індекс шаблону, знайденого в рядку.
Розділяє заданий рядок на масив шляхом поділу рядка на підрядки.
The following script uses the String.prototype.replace()
method to match a name in the format first last and output it in the format last, first.
In the replacement text, the script uses $1
and $2
to indicate the results of the corresponding matching parentheses in the regular expression pattern.
This displays "Cruz, Maria"
.
The default line ending varies depending on the platform (Unix, Windows, etc.). The line splitting provided in this example works on all platforms.
Note that the order of the patterns in the regular expression matters.
The sticky
flag indicates that the regular expression performs sticky matching in the target string by attempting to match starting at RegExp.prototype.lastIndex
.
With the sticky flag y
, the next match has to happen at the lastIndex
position, while with the global flag g
, the match can happen at the lastIndex
position or later:
With the global flag g
, all 6 digits would be matched, not just 3.
\w
and \W
only matches ASCII based characters; for example, a
to z
, A
to Z
, 0
to 9
, and _
.
To match characters from other languages such as Cyrillic or Hebrew, use \uhhhh
, where hhhh
is the character's Unicode value in hexadecimal.
This example demonstrates how one can separate out Unicode characters from a word.
JSCopy to Clipboard
The Unicode property escapes feature provides a simpler way to target particular Unicode ranges, by allowing for statements like \p{scx=Cyrl}
(to match any Cyrillic letter), or \p{L}/u
(to match a letter from any language).
Note: Instead of using regular expressions for parsing URLs, it is usually better to use the browsers built-in URL parser by using the URL API.