Skip to content

StdLib RegExp

Roger Johansson edited this page Jan 14, 2026 · 1 revision

RegExp

The RegExp built-in provides regular expression support.

Implementation Status: 100% Complete

Overview

Category Items Implemented
Constructor 1 1
Static Methods 1 1
Instance Methods 4 4
Symbol Methods 5 5
Property Getters 10 10
Legacy Static Props 12 12
Total 33 33

Constructor

new RegExp(pattern, flags)
new RegExp(regexp)           // Clone with optional new flags
/pattern/flags               // Literal syntax

Static Methods

Method Status Description
RegExp[Symbol.species] Implemented Returns constructor

Instance Methods

Method Status Description
test(string) Implemented Tests for match, returns boolean
exec(string) Implemented Executes search, returns match array
toString() Implemented Returns /pattern/flags string
compile(pattern, flags) Implemented Legacy: recompiles regexp

Symbol Methods

Method Status Description
[Symbol.match](string) Implemented Called by String.match()
[Symbol.matchAll](string) Implemented Called by String.matchAll()
[Symbol.replace](string, repl) Implemented Called by String.replace()
[Symbol.search](string) Implemented Called by String.search()
[Symbol.split](string, limit) Implemented Called by String.split()

Property Getters

Property Status Description
flags Implemented All active flags (alphabetical)
source Implemented Pattern string
global Implemented g flag
ignoreCase Implemented i flag
multiline Implemented m flag
dotAll Implemented s flag
unicode Implemented u flag
unicodeSets Implemented v flag (ES2024)
sticky Implemented y flag
hasIndices Implemented d flag (ES2022)

Supported Flags

Flag Name Description
g global Find all matches
i ignoreCase Case-insensitive
m multiline ^ and $ match line boundaries
s dotAll . matches newlines
u unicode Unicode mode
v unicodeSets Unicode sets mode (ES2024)
y sticky Match at lastIndex only
d hasIndices Include indices in results

Match Result Properties

exec() and match() return arrays with extra properties:

Property Description
[0] Full match
[1..n] Capture groups
index Match position
input Original string
groups Named capture groups object
indices Match indices (with d flag)

Legacy Static Properties

Property Alias Description
RegExp.input $_ Last input string
RegExp.lastMatch $& Last matched substring
RegExp.lastParen $+ Last parenthesized match
RegExp.leftContext $` Text before match
RegExp.rightContext $' Text after match
RegExp.$1 - $9 - Capture group values

Implementation Notes

Pattern Translation

JavaScript patterns are translated to .NET regex with:

  • Unicode support for \u{...} escapes
  • Surrogate pair handling
  • Named group syntax conversion

Unicode Mode (u flag)

  • Full code point matching
  • Surrogate pairs handled correctly
  • Unicode property escapes (\p{...})

Unicode Sets Mode (v flag)

  • Set notation in character classes
  • String literals in character classes
  • Improved Unicode support

lastIndex Behavior

  • Updated after exec() with g or y flag
  • Reset to 0 when match fails
  • Can be set manually

Files

File Purpose
StdLib/RegExp/RegExpConstructor.cs Constructor
StdLib/RegExp/RegExpPrototype.cs Methods and properties
StdLib/RegExp/RegExpHelper.cs Internal helpers
JsTypes/JsRegExp.cs Core implementation

See Also

Clone this wiki locally