Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Intl.Segmenter

Baseline2024
Newly available

TheIntl.Segmenter object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string.

Try it

const segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });const string1 = "Que ma joie demeure";const iterator1 = segmenterFr.segment(string1)[Symbol.iterator]();console.log(iterator1.next().value.segment);// Expected output: 'Que'console.log(iterator1.next().value.segment);// Expected output: ' '

Constructor

Intl.Segmenter()

Creates a newIntl.Segmenter object.

Static methods

Intl.Segmenter.supportedLocalesOf()

Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties

These properties are defined onIntl.Segmenter.prototype and shared by allIntl.Segmenter instances.

Intl.Segmenter.prototype.constructor

The constructor function that created the instance object. ForIntl.Segmenter instances, the initial value is theIntl.Segmenter constructor.

Intl.Segmenter.prototype[Symbol.toStringTag]

The initial value of the[Symbol.toStringTag] property is the string"Intl.Segmenter". This property is used inObject.prototype.toString().

Instance methods

Intl.Segmenter.prototype.resolvedOptions()

Returns a new object with properties reflecting the locale and granularity options computed during initialization of thisIntl.Segmenter object.

Intl.Segmenter.prototype.segment()

Returns a new iterableSegments instance representing the segments of a string according to the locale and granularity of thisIntl.Segmenter instance.

Examples

Basic usage and difference from String.prototype.split()

If we were to useString.prototype.split(" ") to segment a text in words, we would not get the correct result if the locale of the text does not use whitespaces between words (which is the case for Japanese, Chinese, Thai, Lao, Khmer, Myanmar, etc.).

js
const str = "吾輩は猫である。名前はたぬき。";console.table(str.split(" "));// ['吾輩は猫である。名前はたぬき。']// The two sentences are not correctly segmented.
js
const str = "吾輩は猫である。名前はたぬき。";const segmenterJa = new Intl.Segmenter("ja-JP", { granularity: "word" });const segments = segmenterJa.segment(str);console.table(Array.from(segments));// [{segment: '吾輩', index: 0, input: '吾輩は猫である。名前はたぬき。', isWordLike: true},// etc.// ]

Specifications

Specification
ECMAScript® 2026 Internationalization API Specification
# segmenter-objects

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp