/** * useRegexTester Hook * * @module RegexEditor/hooks/useRegexTester * @description 提供正则测试功能的 React Hook */ import type { RegexFlags, MatchResult } from '../visualizer/types'; /** * Hook 配置选项 */ export interface UseRegexTesterOptions { /** 初始测试文本 */ initialTestText?: string; /** 初始标志 */ initialFlags?: RegexFlags; /** 最大匹配数量 */ maxMatches?: number; /** 匹配超时时间 (毫秒) */ matchTimeout?: number; /** 匹配结果回调 */ onMatchResults?: (results: MatchResult[]) => void; /** 防抖延迟 (毫秒) */ debounceDelay?: number; } /** * Hook 返回值 */ export interface UseRegexTesterResult { /** 测试文本 */ testText: string; /** 设置测试文本 */ setTestText: (text: string) => void; /** 标志 */ flags: RegexFlags; /** 设置标志 */ setFlags: (flags: RegexFlags) => void; /** 匹配结果 */ matches: MatchResult[]; /** 是否正在匹配 */ isMatching: boolean; /** 匹配错误 */ error: string | null; /** 是否有效的正则表达式 */ isValid: boolean; /** 清空测试文本 */ clearTestText: () => void; /** 重新匹配 */ rematch: () => void; } /** * 正则测试 Hook * * @param pattern - 正则表达式模式 * @param options - 配置选项 * @returns Hook 结果 * * @example * ```tsx * const { * testText, * setTestText, * flags, * setFlags, * matches, * isValid, * } = useRegexTester(pattern, { * initialTestText: 'test@example.com', * initialFlags: { global: true }, * }); * ``` */ export declare function useRegexTester(pattern: string, options?: UseRegexTesterOptions): UseRegexTesterResult; /** * 替换预览 Hook * * @param pattern - 正则表达式模式 * @param text - 原始文本 * @param replaceText - 替换文本 * @param flags - 标志 * @returns 替换结果和错误 * * @example * ```tsx * const { result, error } = useReplacePreview( * '(\\d+)', * 'abc 123 def', * 'NUM:$1', * { global: true } * ); * ``` */ export declare function useReplacePreview(pattern: string, text: string, replaceText: string, flags?: RegexFlags): { result: string | null; error: string | null; };