Skip to content
Eugene Lazutkin edited this page Nov 8, 2026 · 1 revision

Helpers

RE2 adds two static helpers and one property to the RegExp interface.

const RE2 = require('re2');

RE2.getUtf8Length('привет'); // 12
RE2.getUtf16Length(Buffer.from('привет')); // 6

new RE2(/\p{Letter}+/u).internalSource; // '\\pL+'

Calculate length

Two helpers convert between UTF-8 and UTF-16 sizes:

  • RE2.getUtf8Length(str) — byte size needed to encode a string as a UTF-8 buffer.
  • RE2.getUtf16Length(buf) — character count needed to decode a UTF-8 buffer as a string.

Property: internalSource

source emulates the standard RegExp property and can recreate an identical RE2 or RegExp instance. To inspect the RE2-translated pattern, which is useful for debugging, use the read-only internalSource property.

Clone this wiki locally