Skip to content

patternInOutCapture

patternInOutCapture(pattern, options?): string

Defined in: packages/core/src/pattern/pattern-util.ts:55

Enclose the pattern with in-out capture groups, provided pre/post pattern strings.

inCaptureName is the name of the inner capture group (the main pattern). outCaptureName is the name of the outer capture group (the whole pattern with pre/post).

If inCaptureName is not provided, the inner capture group will be non-capturing. If outCaptureName is not provided, the outer capture group will be non-capturing.

The prePattern and postPattern are added before and after the main pattern, respectively.

Exemple:

const pattern = patternInOutCapture("\\d+", {
prePattern: "\\(",
postPattern: "\\)",
inCaptureName: "number",
outCaptureName: "parenthesizedNumber",
});
// pattern is "(?<(parenthesizedNumber)>(?:\\((?<number>\\d+)\\)))"
// new RegExp(pattern) is /(?(<parenthesizedNumber>)(?:\((?<number>\d+)\)))/

string

The main pattern to be captured.

PatternInOutCaptureOptions = {}

Options for pre/post patterns and capture group names.

string

The composed pattern string with in-out capture groups.