Skip to content

match

Instance method on String.prototype.

Matches a string with a regular expression, and returns an array containing the results of that search.

Matches a string or an object that supports being matched against, and returns an array containing the results of that search, or null if no matches are found.

match(input: { string: <receiver>; regexp: string | RegExp; prompt?: string }): Promise<RegExpMatchArray>
match(input: { string: <receiver>; matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }; prompt?: string }): Promise<RegExpMatchArray>

The prompt field is optional. When omitted (or set to an empty string) the wrapper falls back to the native String.prototype.match and returns a resolved Promise without contacting the LLM. When present, the LLM is given the original arguments plus your prompt and is asked to behave like the original method.

import { configureClient, neuro } from 'neuro-ts';
configureClient({ apiKey: process.env.OPENAI_API_KEY });
// Regex match; the global flag changes the return shape, which is a feature in exactly one direction.
await neuro.string.match({ string: input, regexp: /(d+)/, prompt: 'execute regexp against the string, returning the match array or null, and let the global flag silently change the return shape behind your back' });

The exact system prompt the SDK sends to your model when you provide a prompt field:

Generated promptString.prototype.match
You are simulating the JavaScript built-in `String.prototype.match`.
## Original signature(s)
  Overload 1: (regexp: string | RegExp) => RegExpMatchArray
  Overload 2: (matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }) => RegExpMatchArray
## JSDoc
Matches a string with a regular expression, and returns an array containing the results of that search.

## How to respond
- Behave EXACTLY as the original `match` would, but use the user's intent to choose any callback / comparator / transform logic that the original would normally accept as an argument.
- Strictly preserve the original return type and shape.
- Output ONLY the JSON-encoded return value of the function call.
- Do NOT include explanations, prose, comments, or markdown fences.
- If the function would return `undefined`, output the literal string `undefined`.
- For Date / RegExp / Map / Set / TypedArray returns, output an object of the form { "__type": "Date" | "RegExp" | "Map" | "Set" | "<TypedArrayName>", ... } so the SDK can rehydrate it.