> 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/prim/str/method/str.matchall/words-in-sentence.md).

# words in sentence

🚧 under construction

[JS](/web/js.md) ⟩ [primitives](/web/js/val/prim.md) ⟩ [String](/web/js/val/prim/str.md) ⟩ [methods](/web/js/val/prim/str/method.md) ⟩ [.matchAll()](/web/js/val/prim/str/method/str.matchall.md) ⟩ words in sentence

{% hint style="success" %}
desc.
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}
:floppy\_disk: replit：[words in sentence](https://replit.com/@pegasusroe/matchAll-words-in-a-string#index.js)

```javascript
// ⭐️ Unicode "alphabetic characters" between word boundaries 
const word = /\b\p{Alphabetic}+\b/gu;     // \p is not supported in Firefox yet❗

const text = `
    This is a naïve test of the matchAll() method.
    這裡中文字
    ✏️ うわ、喧嘩してる！何かあったんですか？
`; // ⭐️ Chinese and Japanese characters are NOT "alphabetic characters"❗

// ⭐️ (iterable) iterator of all matches (words)
const matches = text.matchAll(word);

// iterate using for-of loop
for(let match of matches) { 
    console.log(`${(match.index + '').padStart(3, '0')}: '${match[0]}'`);
    //              ╰──index──╯                             ╰─word─╯
}

// output
// --------------
// 005: 'This'
// 010: 'is'
// 013: 'a'
// 015: 'naïve'
// 021: 'test'
// 026: 'of'
// 029: 'the'
// 033: 'matchAll'
// 044: 'method'
```

{% endtab %}

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

* [ ] JavaScript: The Definitive Guide ⟩ 11.3.2 String Methods for Pattern Matching
  {% endtab %}

{% tab title="👥 相關" %}

* [str.matchAll()](/web/js/val/prim/str/method/str.matchall.md) returns an [iterable iterator](/web/js/iteration/iterator/iterable.md).
* [RegExp](/web/js/val/builtin/regex.md)
  {% endtab %}
  {% endtabs %}
