Skip to content

Commit 86349af

Browse files
committed
Fix description of regex flags
1 parent f82233a commit 86349af

File tree

8 files changed

+57
-51
lines changed

8 files changed

+57
-51
lines changed

files/en-us/web/javascript/reference/global_objects/regexp/dotall/index.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
2-
title: RegExp.prototype.dotAll
2+
title: get RegExp.prototype.dotAll
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/dotAll
44
tags:
5-
- Draft
65
- JavaScript
76
- Property
87
- Prototype
@@ -14,15 +13,13 @@ browser-compat: javascript.builtins.RegExp.dotAll
1413
---
1514
{{JSRef}}
1615

17-
The **`dotAll`** property indicates whether or not the `s` flag is used with the regular expression. `dotAll` is a read-only property of an individual regular expression instance.
16+
The **`dotAll`** accessor property indicates whether or not the `s` flag is used with the regular expression.
1817

1918
{{EmbedInteractiveExample("pages/js/regexp-prototype-dotall.html")}}
2019

21-
{{JS_Property_Attributes(0, 0, 1)}}
22-
2320
## Description
2421

25-
The value of `dotAll` is a {{JSxRef("Boolean")}} and `true` if the `s` flag was used; otherwise, `false`. The `s` flag indicates that the dot special character (`.`) should additionally match the following line terminator ("newline") characters in a string, which it would not match otherwise:
22+
`RegExp.prototype.dotAll` is a getter-only property that returns `true` if the `s` flag was used; otherwise, `false`. The `s` flag indicates that the dot special character (`.`) should additionally match the following line terminator ("newline") characters in a string, which it would not match otherwise:
2623

2724
- U+000A LINE FEED (LF) (`\n`)
2825
- U+000D CARRIAGE RETURN (CR) (`\r`)
@@ -35,20 +32,20 @@ You cannot change this property directly.
3532

3633
## Examples
3734

38-
### Using `dotAll`
35+
### Using dotAll
3936

4037
```js
4138
const str1 = 'bar\nexample foo example';
4239

43-
const regex1 = new RegExp('bar.example','s');
40+
const regex1 = /bar.example/s;
4441

4542
console.log(regex1.dotAll); // Output: true
4643

47-
console.log(str1.replace(regex1,'')); // Output: foo example
44+
console.log(str1.replace(regex1, '')); // Output: foo example
4845

4946
const str2 = 'bar\nexample foo example';
5047

51-
const regex2 = new RegExp('bar.example');
48+
const regex2 = /bar.example/;
5249

5350
console.log(regex2.dotAll); // Output: false
5451

files/en-us/web/javascript/reference/global_objects/regexp/flags/index.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: RegExp.prototype.flags
2+
title: get RegExp.prototype.flags
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/flags
44
tags:
55
- ECMAScript 2015
@@ -14,15 +14,17 @@ browser-compat: javascript.builtins.RegExp.flags
1414
---
1515
{{JSRef}}
1616

17-
The **`flags`** property returns a string consisting of the [flags](/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags) of the current regular expression object.
17+
The **`flags`** accessor property represents the [flags](/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags) of the current regular expression object.
1818

1919
{{EmbedInteractiveExample("pages/js/regexp-prototype-flags.html")}}
2020

21-
{{JS_Property_Attributes(0, 0, 1)}}
22-
2321
## Description
2422

25-
Flags in the `flags` property are sorted alphabetically (from left to right, e.g. `"gimsuy"`).
23+
`RegExp.prototype.flags` is a getter-only property that returns a string. Flags in the `flags` property are sorted alphabetically (from left to right, e.g. `"dgimsuy"`). It actually invokes the other flag accessors ([`hasIndices`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices), [`global`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global), etc.) one-by-one and concatenates the results.
24+
25+
All built-in functions read the `flags` property instead of reading individual flag accessors.
26+
27+
You cannot change this property directly.
2628

2729
## Examples
2830

files/en-us/web/javascript/reference/global_objects/regexp/global/index.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: RegExp.prototype.global
2+
title: get RegExp.prototype.global
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/global
44
tags:
55
- JavaScript
@@ -12,13 +12,15 @@ browser-compat: javascript.builtins.RegExp.global
1212
---
1313
{{JSRef}}
1414

15-
The **`global`** property indicates whether or not the `g` flag is used with the regular expression. `global` is a read-only property of an individual regular expression instance.
15+
The **`global`** accessor property indicates whether or not the `g` flag is used with the regular expression.
1616

17-
{{EmbedInteractiveExample("pages/js/regexp-prototype-global.html")}}{{js_property_attributes(0, 0, 1)}}
17+
{{EmbedInteractiveExample("pages/js/regexp-prototype-global.html")}}
1818

1919
## Description
2020

21-
The value of `global` is a {{jsxref("Boolean")}} and `true` if the `g` flag was used; otherwise, `false`. The `g` flag indicates that the regular expression should be tested against all possible matches in a string. A regular expression defined as both `global` (`g`) and `sticky` (`y`) will ignore the `global` flag and perform sticky matches.
21+
`RegExp.prototype.global` is a getter-only property that returns `true` if the `g` flag was used; otherwise, `false`. The `g` flag indicates that the regular expression should be tested against all possible matches in a string. Each call to [`exec()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) will update its [`lastIndex`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) property, so that the next call to `exec()` will start at the next character.
22+
23+
Some methods, such as [`String.prototype.matchAll()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll) and [`String.prototype.replaceAll()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll), will validate that, if the parameter is a regex, it is global. The regex's [`@@match`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@match) and [`@@replace`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@replace) methods (called by [`String.prototype.match()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) and [`String.prototype.replace()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)) would also have different behaviors when the regex is global.
2224

2325
You cannot change this property directly.
2426

@@ -27,7 +29,7 @@ You cannot change this property directly.
2729
### Using global
2830

2931
```js
30-
const regex = new RegExp('foo', 'g');
32+
const regex = /foo/g;
3133

3234
console.log(regex.global); // true
3335

@@ -37,7 +39,7 @@ const str1 = str.replace(regex, '');
3739

3840
console.log(str1); // Output: example
3941

40-
const regex1 = new RegExp('foo');
42+
const regex1 = /foo/;
4143

4244
const str2 = str.replace(regex1, '');
4345

files/en-us/web/javascript/reference/global_objects/regexp/hasindices/index.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
2-
title: RegExp.prototype.hasIndices
2+
title: get RegExp.prototype.hasIndices
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices
44
tags:
5-
- Draft
65
- JavaScript
76
- Property
87
- Prototype
@@ -13,26 +12,24 @@ browser-compat: javascript.builtins.RegExp.hasIndices
1312
---
1413
{{JSRef}}
1514

16-
The **`hasIndices`** property indicates whether or not the `d` flag is used with the regular expression. `hasIndices` is a read-only property of an individual regular expression instance.
15+
The **`hasIndices`** accessor property indicates whether or not the `d` flag is used with the regular expression.
1716

1817
{{EmbedInteractiveExample("pages/js/regexp-prototype-hasindices.html")}}
1918

20-
{{JS_Property_Attributes(0, 0, 1)}}
21-
2219
## Description
2320

24-
The value of `hasIndices` is a {{JSxRef("Boolean")}} and `true` if the `d` flag was used; otherwise, `false`. The `d` flag indicates that the result of a regular expression match should contain the start and end indices of the substrings of each capture group.
21+
`RegExp.prototype.hasIndices` is a getter-only property that returns `true` if the `d` flag was used; otherwise, `false`. The `d` flag indicates that the result of a regular expression match should contain the start and end indices of the substrings of each capture group. It does not change the regex's interpretation or matching behavior in any way, but only enables additional information in the matching result.
2522

2623
You cannot change this property directly.
2724

2825
## Examples
2926

30-
### Using `hasIndices`
27+
### Using hasIndices
3128

3229
```js
3330
const str1 = 'foo bar foo';
3431

35-
const regex1 = new RegExp('foo', 'gd');
32+
const regex1 = /foo/gd;
3633

3734
console.log(regex1.hasIndices); // Output: true
3835

@@ -41,7 +38,7 @@ console.log(regex1.exec(str1).indices[0]); // Output: Array [8, 11]
4138

4239
const str2 = 'foo bar foo';
4340

44-
const regex2 = new RegExp('foo');
41+
const regex2 = /foo/;
4542

4643
console.log(regex2.hasIndices); // Output: false
4744

files/en-us/web/javascript/reference/global_objects/regexp/ignorecase/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: RegExp.prototype.ignoreCase
2+
title: get RegExp.prototype.ignoreCase
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase
44
tags:
55
- JavaScript
@@ -12,13 +12,13 @@ browser-compat: javascript.builtins.RegExp.ignoreCase
1212
---
1313
{{JSRef}}
1414

15-
The **`ignoreCase`** property indicates whether or not the `i` flag is used with the regular expression. `ignoreCase` is a read-only property of an individual regular expression instance.
15+
The **`ignoreCase`** accessor property indicates whether or not the `i` flag is used with the regular expression.
1616

17-
{{EmbedInteractiveExample("pages/js/regexp-prototype-ignorecase.html")}}{{js_property_attributes(0, 0, 1)}}
17+
{{EmbedInteractiveExample("pages/js/regexp-prototype-ignorecase.html")}}
1818

1919
## Description
2020

21-
The value of `ignoreCase` is a {{jsxref("Boolean")}} and `true` if the `i` flag was used; otherwise, `false`. The `i` flag indicates that case should be ignored while attempting a match in a string.
21+
`RegExp.prototype.ignoreCase` is a getter-only property that returns `true` if the `i` flag was used; otherwise, `false`. The `i` flag indicates that case should be ignored while attempting a match in a string.
2222

2323
You cannot change this property directly.
2424

@@ -27,7 +27,7 @@ You cannot change this property directly.
2727
### Using ignoreCase
2828

2929
```js
30-
const regex = new RegExp('foo', 'i');
30+
const regex = /foo/i;
3131

3232
console.log(regex.ignoreCase); // true
3333
```

files/en-us/web/javascript/reference/global_objects/regexp/multiline/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: RegExp.prototype.multiline
2+
title: get RegExp.prototype.multiline
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/multiline
44
tags:
55
- JavaScript
@@ -12,13 +12,13 @@ browser-compat: javascript.builtins.RegExp.multiline
1212
---
1313
{{JSRef}}
1414

15-
The **`multiline`** property indicates whether or not the `m` flag is used with the regular expression. `multiline` is a read-only property of an individual regular expression instance.
15+
The **`multiline`** accessor property indicates whether or not the `m` flag is used with the regular expression.
1616

17-
{{EmbedInteractiveExample("pages/js/regexp-prototype-multiline.html", "taller")}}{{js_property_attributes(0, 0, 1)}}
17+
{{EmbedInteractiveExample("pages/js/regexp-prototype-multiline.html", "taller")}
1818

1919
## Description
2020

21-
The value of `multiline` is a {{jsxref("Boolean")}} and is true if the `m` flag was used; otherwise, false. The `m` flag indicates that a multiline input string should be treated as multiple lines. For example, if `m` is used, `^` and `$` change from matching at only the start or end of the entire string to the start or end of any line within the string.
21+
`RegExp.prototype.multiline` is a getter-only property that returns `true` if the `m` flag was used; otherwise, `false`. The `m` flag indicates that a multiline input string should be treated as multiple lines. For example, if `m` is used, `^` and `$` change from matching at only the start or end of the entire string to the start or end of any line within the string.
2222

2323
You cannot change this property directly.
2424

@@ -27,7 +27,7 @@ You cannot change this property directly.
2727
### Using multiline
2828

2929
```js
30-
const regex = new RegExp('foo', 'm');
30+
const regex = /foo/m;
3131

3232
console.log(regex.multiline); // true
3333
```

files/en-us/web/javascript/reference/global_objects/regexp/sticky/index.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: RegExp.prototype.sticky
2+
title: get RegExp.prototype.sticky
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/sticky
44
tags:
55
- ECMAScript 2015
@@ -14,15 +14,19 @@ browser-compat: javascript.builtins.RegExp.sticky
1414
---
1515
{{JSRef}}
1616

17-
The **`sticky`** property reflects whether or not the search is sticky (searches in strings only from the index indicated by the {{jsxref("RegExp.lastIndex", "lastIndex")}} property of this regular expression). `sticky` is a read-only property of an individual regular expression object.
17+
The **`sticky`** accessor property indicates whether or not the `y` flag is used with the regular expression.
1818

19-
{{EmbedInteractiveExample("pages/js/regexp-prototype-sticky.html", "taller")}}{{js_property_attributes(0, 0, 1)}}
19+
{{EmbedInteractiveExample("pages/js/regexp-prototype-sticky.html", "taller")}}
2020

2121
## Description
2222

23-
The value of `sticky` is a {{jsxref("Boolean")}} and true if the `y` flag was used; otherwise, false. The `y` flag indicates that it matches only from the index indicated by the {{jsxref("RegExp.lastIndex", "lastIndex")}} property of this regular expression in the target string (and does not attempt to match from any later indexes). A regular expression defined as both `sticky` and `global` ignores the `global` flag.
23+
`RegExp.prototype.sticky` is a getter-only property that returns `true` if the `y` flag was used; otherwise, `false`. The `y` flag indicates that it matches only from the index indicated by the {{jsxref("RegExp.lastIndex", "lastIndex")}} property of this regular expression in the target string (and does not attempt to match from any later indexes).
2424

25-
You cannot change this property directly. It is read-only.
25+
When the [`exec()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method is called and the regex fails to match at the current position indicated by {{jsxref("RegExp.lastIndex", "lastIndex")}}, a global regex will continue to attempt at the next character, while a sticky regex immediately returns `null` and resets `lastIndex` to 0. When the match succeeds, `lastIndex` is advanced to the end of the match, just like global regexps do. When `lastIndex` is out of bounds of the currently matched string, it's reset to 0, just like global regexps do.
26+
27+
For the [`exec()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method, a regex that's both sticky and [global](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global) behaves the same as a sticky and non-global regex. However, due to many other methods special-casing the behavior of global regexps, the global flag is, in general, orthogonal to the sticky flag. For more information about how each individual regex-related method (such as [`String.prototype.match()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) and [`String.prototype.replace()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)) interact with the sticky and global flags, see their respective pages.
28+
29+
You cannot change this property directly.
2630

2731
## Examples
2832

files/en-us/web/javascript/reference/global_objects/regexp/unicode/index.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: RegExp.prototype.unicode
2+
title: get RegExp.prototype.unicode
33
slug: Web/JavaScript/Reference/Global_Objects/RegExp/unicode
44
tags:
55
- ECMAScript 2015
@@ -13,22 +13,26 @@ browser-compat: javascript.builtins.RegExp.unicode
1313
---
1414
{{JSRef}}
1515

16-
The **`unicode`** property indicates whether or not the `u` flag is used with a regular expression. `unicode` is a read-only property of an individual regular expression instance.
16+
The **`unicode`** accessor property indicates whether or not the `u` flag is used with the regular expression.
1717

18-
{{EmbedInteractiveExample("pages/js/regexp-prototype-unicode.html", "taller")}}{{js_property_attributes(0, 0, 1)}}
18+
{{EmbedInteractiveExample("pages/js/regexp-prototype-unicode.html", "taller")}}
1919

2020
## Description
2121

22-
The value of `unicode` is a {{jsxref("Boolean")}} and `true` if the `u` flag was used; otherwise `false`. The `u` flag enables various Unicode-related features. With the "u" flag, any Unicode code point escapes will be interpreted as such, for example.
22+
`RegExp.prototype.unicode` is a getter-only property that returns `true` if the `u` flag was used; otherwise, `false`. The `u` flag enables various Unicode-related features. With the "u" flag:
2323

24-
You cannot change this property directly. It is read-only.
24+
- Any [Unicode codepoint escapes](/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes) (`\u{xxxx}`, `\p{UnicodePropertyValue}`) will be interpreted as such instead of literal characters.
25+
- Surrogate pairs will be interpreted as whole characters instead of two separate characters. For example, `/[😄]/u` would only match `"😄"` but not `"\ud83d"`.
26+
- When [`lastIndex`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) is automatically advanced (such as when calling [`exec()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)), unicode regexps advance by Unicode codepoints instead of UTF-16 code units.
27+
28+
You cannot change this property directly.
2529

2630
## Examples
2731

2832
### Using the unicode property
2933

3034
```js
31-
const regex = new RegExp('\u{61}', 'u');
35+
const regex = /\u{61}/u;
3236

3337
console.log(regex.unicode); // true
3438
```

0 commit comments

Comments
 (0)