Regex Input
Validate regular expressions live with flags toggles, error feedback, and match previews.
user_alice@drift-ui.dev logged in from 192.168.1.10
support+urgent@example.org reported issue #404
invalid-address@@test
sales@lumenhq.io requested a demoKeyboard
- SpaceEnter
- Toggle the focused flag button
- Tab
- Move focus between pattern input and flag buttons
Installation
The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.
Usage
"use client"
import { useState } from "react"
import { RegexInput } from "@/components/ui/regex-input"
export function LogPatternFilter() {
const [pattern, setPattern] = useState("\\[(ERROR|WARN)\\]\\s+(?<message>.*)")
const [flags, setFlags] = useState("i")
return (
<RegexInput
aria-label="Log filter regex"
value={pattern}
onValueChange={setPattern}
flags={flags}
onFlagsChange={setFlags}
sample="[2026-05-18] [ERROR] Database connection lost"
placeholder="Type regex pattern..."
/>
)
}Examples
Default
Pattern input with flag toggles, live match highlight, and count badge.
Deploying service v1.4.2 to production
Failed to start worker v2.0.0-beta.1
Hotfix v1.4.3 applied successfullyCapture groups
Inspect named capture groups per match.
Created order #1042 on 2026-05-18 for $120.50
Created order #1043 on 2026-05-19 for $89.00Log filter
Match severity levels and extract messages from real-world server logs.
[2026-05-18T10:14:02Z] [INFO] Request completed in 24ms
[2026-05-18T10:14:05Z] [WARN] Connection pool reaching capacity (85%)
[2026-05-18T10:14:09Z] [ERROR] Database timeout on replica-02
[2026-05-18T10:14:12Z] [ERROR] Health check failed for redis-cacheAPI reference
RegexInput
A live regular expression pattern input with flags toggles, syntax error feedback, configurable match limits, sample text match highlights, and capture groups inspection.
| Prop | Type | Default |
|---|---|---|
valuestringControlled regex pattern string (without slash delimiters). | string | |
defaultValuestringDefault""Initial regex pattern string when uncontrolled. | string | "" |
onValueChange(pattern: string) => voidCalled when the pattern changes. | (pattern: string) => void | |
flagsstringControlled active flags string, such as "i", "m", "ims". | string | |
defaultFlagsstringDefault""Initial flags string when uncontrolled. | string | "" |
onFlagsChange(flags: string) => voidCalled when active flags change. | (flags: string) => void | |
availableFlagsreadonly string[]Default["i", "m", "s"]Flag toggle buttons to show next to the input. | readonly string[] | ["i", "m", "s"] |
samplestringSample text to test the pattern against and highlight matches. | string | |
placeholderstringDefault"pattern"Placeholder text for the pattern input. | string | "pattern" |
disabledbooleanDefaultfalseDisables the pattern input and flag toggles. | boolean | false |
readOnlybooleanDefaultfalseMakes the pattern input and flag toggles read-only. | boolean | false |
namestringForm field name for submitting the pattern through a hidden input. | string | |
showDelimitersbooleanDefaulttrueWhether to display leading and trailing slashes (/ ... /). | boolean | true |
showFlagsbooleanDefaulttrueWhether to display flag toggle buttons. | boolean | true |
showErrorbooleanDefaulttrueWhether to render constructor syntax errors below the input. | boolean | true |
showSamplePreviewbooleanDefaulttrueWhether to display highlighted sample text and capture groups. | boolean | true |
maxMatchesnumberDefault100Cap on number of matches to find in the sample. | number | 100 |
maxSampleLengthnumberDefault20000Cap on sample text character length for matching. | number | 20000 |
inputRefReact.Ref<HTMLInputElement>Ref forwarded to the pattern input element. | React.Ref<HTMLInputElement> | |
inputPropsOmit<React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "disabled" | "readOnly">Additional props forwarded to the underlying text input element. | Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "disabled" | "readOnly"> |
Other props go to the <div>.
validateRegex, findRegexMatches, findRegexMatchesAsync, highlightSampleText, toggleFlag, normalizeFlags
validateRegex(pattern: string, flags?: string): RegexValidationResult; findRegexMatches(pattern: string, flags: string, sample: string, options?: RegexMatchOptions): RegexMatchResult; findRegexMatchesAsync(pattern: string, flags: string, sample: string, options?: RegexMatchOptions & { signal?: AbortSignal }): Promise<RegexMatchResult>; highlightSampleText(sample: string, matches: RegexMatch[]): RegexSegment[]; toggleFlag(flags: string, flag: string): string; normalizeFlags(flags: string): stringPure logic functions for validating patterns, length- and match-capped regex execution (with interruptible Web Worker support via findRegexMatchesAsync), sample text segmenting, and flag manipulation. Import from @/lib/regex-input-utils.