---
description: 🚧 under construction
---

# regex flag

[JS](../../..) ⟩ [value](../..) ⟩ [object](../../obj) ⟩ [regex]() ⟩ flag

{% hint style="success" %}
```javascript
/abc/igd	     // ignnore case, global search, generate indices
```
{% endhint %}

<table><thead><tr><th width="100">flag</th><th>description</th><th>corresponding property</th></tr></thead><tbody><tr><td><a href="flag/d"><strong><code>d</code></strong></a></td><td>generate <mark style="color:yellow;"><strong>indices</strong></mark> for substring matches.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices"><code>hasIndices</code></a></td></tr><tr><td><a href="flag/flag-u"><strong><code>u</code></strong></a></td><td>treat a pattern as a sequence of <mark style="color:yellow;"><strong>Unicode</strong></mark> <a href="../../prim/str/unicode/code-point"><mark style="color:yellow;"><strong>code points</strong></mark></a>.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode"><code>unicode</code></a></td></tr><tr><td><code>g</code></td><td><mark style="color:yellow;"><strong>global</strong></mark> search.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global"><code>global</code></a></td></tr><tr><td><code>i</code></td><td><mark style="color:yellow;"><strong>ignore</strong></mark> case.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase"><code>ignoreCase</code></a></td></tr><tr><td><code>m</code></td><td>allows <mark style="color:yellow;"><code>^</code></mark> and <mark style="color:yellow;"><code>$</code></mark> to match <mark style="color:yellow;"><strong>newline</strong></mark>.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline"><code>multiline</code></a></td></tr><tr><td><code>s</code></td><td>allows <mark style="color:yellow;"><code>.</code></mark> to match <mark style="color:yellow;"><strong>newline</strong></mark>.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll"><code>dotAll</code></a></td></tr><tr><td><code>y</code></td><td>"<mark style="color:yellow;"><strong>sticky</strong></mark>" search:  matches starting at the current position in the target string.</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky"><code>sticky</code></a></td></tr></tbody></table>

{% tabs %}
{% tab title="🧨 雷區" %}
{% hint style="danger" %}
when using [str.matchAll(regex)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll), the <mark style="color:blue;">`regex`</mark> <mark style="color:red;">**must**</mark>**&#x20;**<mark style="color:yellow;">**have**</mark> the <mark style="color:orange;">**global**</mark> (<mark style="color:yellow;">**`g`**</mark>) [**flag**](flag) set, or a [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) is thrown:exclamation:
{% endhint %}
{% endtab %}

{% tab title="💈範例" %}
* 💈範例：
  * [quick-brown-fox](ex/quick-brown-fox "mention") - example for <mark style="color:yellow;">`d`</mark>, <mark style="color:yellow;">`g`</mark>, <mark style="color:yellow;">`i`</mark> flags.&#x20;

```javascript
// code
```
{% endtab %}

{% tab title="📗 參考" %}
* [ ] Eloquent JS ⟩ Regular Expressions ⟩&#x20;
  * [ ] [Sets of Characters](https://eloquentjavascript.net/09_regexp.html#h_8EFR0DU1xd)
  * [ ] [lastIndex](https://eloquentjavascript.net/09_regexp.html#h_duFTd2hqd0)
{% endtab %}

{% tab title="📘 手冊" %}
* [JavaScript Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide) ⟩ [Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) ⟩ [Advanced searching with flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags)
{% endtab %}
{% endtabs %}
