# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/val/builtin/regex/pattern/repeat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
