> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/builtin/regex/pattern/repeat.md).

# repeat

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [object](/web/js/val/obj.md) ⟩ [regex](/web/js/val/builtin/regex.md) ⟩ [pattern](/web/js/val/builtin/regex/pattern.md) ⟩ repeat

{% hint style="success" %}

```regex
         repeat   regex       matches
------------------------------------------------------
?	 0 ~ 1    colou?r     color colour
*        0 ~ ∞    b\w*        b be bee beer beers
+        1 ~ ∞    b\w+        be bee beer beers

{2,3}    2 ~ 3    b\w{2,3}    bee beer beers
{3}      3
{3,}     3 ~ ∞

// quantifiers are normally greedy (match as much as possible)
// when followed by ? they become lazy (match as little as possible)
+?       lazy     b\w+?       be bee beer beers         (as few as possible)
                              ╰╯ ╰╯  ╰╯   ╰╯
```

:u6307: <mark style="color:yellow;">**synonyms**</mark>： "<mark style="color:purple;">**quantifier**</mark>", "<mark style="color:purple;">**repetition operator**</mark>"
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
When using a <mark style="color:purple;">**repetition operator**</mark>, consider the [<mark style="color:yellow;">**lazy**</mark>](/web/js/val/builtin/regex/pattern/repeat/greedy-vs.-lazy.md) variant <mark style="color:red;">**first**</mark>.
{% endhint %}
{% endtab %}

{% tab title="💈範例" %}

```javascript
// code
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] Eloquent JavaScript ⟩ Regular Expressions ⟩ [Sets of Characters](https://eloquentjavascript.net/09_regexp.html#h_8EFR0DU1xd)
* [ ] [Regular Expression Quick Reference](http://regexrenamer.sourceforge.net/help/regex_quickref.html)
  {% endtab %}
  {% endtabs %}
