/** * 正则表达式可视化 - 工具函数 * * @module RegexEditor/visualizer/utils * @description 提供匹配、标志转换等工具函数 */ import type { RegexFlags, MatchResult } from './types'; /** * 将标志对象转换为标志字符串 * * @param flags - 标志对象 * @returns 标志字符串 (如 "gim") * * @example * ```ts * flagsToString({ global: true, ignoreCase: true }) * // => "gi" * ``` */ export declare function flagsToString(flags?: RegexFlags): string; /** * 将标志字符串转换为标志对象 * * @param flagsStr - 标志字符串 (如 "gim") * @returns 标志对象 * * @example * ```ts * stringToFlags("gi") * // => { global: true, ignoreCase: true } * ``` */ export declare function stringToFlags(flagsStr: string): RegexFlags; /** * 执行正则匹配并返回所有匹配结果 * * @param pattern - 正则表达式模式 * @param text - 测试文本 * @param flags - 标志 * @param maxMatches - 最大匹配数量限制 * @param timeout - 超时时间 (毫秒) * @returns 匹配结果数组,如果出错返回 null * * @example * ```ts * const results = performMatch('\\d+', 'abc 123 def 456', { global: true }); * // => [ * // { index: 4, lastIndex: 7, fullMatch: '123', groups: ['123'] }, * // { index: 12, lastIndex: 15, fullMatch: '456', groups: ['456'] } * // ] * ``` */ export declare function performMatch(pattern: string, text: string, flags?: RegexFlags, maxMatches?: number, timeout?: number): MatchResult[] | null; /** * 执行正则替换并返回结果 * * @param pattern - 正则表达式模式 * @param text - 原始文本 * @param replaceText - 替换文本 (支持 $1, $2 等) * @param flags - 标志 * @returns 替换后的文本,如果出错返回 null * * @example * ```ts * performReplace('(\\d+)', 'abc 123 def', 'NUM:$1', { global: true }) * // => "abc NUM:123 def" * ``` */ export declare function performReplace(pattern: string, text: string, replaceText: string, flags?: RegexFlags): string | null; /** * 高亮文本中的匹配部分 * * @param text - 原始文本 * @param matches - 匹配结果数组 * @returns 带高亮标记的 HTML 字符串 * * @example * ```ts * highlightMatches('abc 123 def', [ * { index: 4, lastIndex: 7, fullMatch: '123', groups: ['123'] } * ]) * // => 'abc 123 def' * ``` */ export declare function highlightMatches(text: string, matches: MatchResult[]): string; /** * 格式化匹配位置 * * @param match - 匹配结果 * @returns 格式化的位置字符串 * * @example * ```ts * formatPosition({ index: 10, lastIndex: 15, ... }) * // => "10-15" * ``` */ export declare function formatPosition(match: MatchResult): string; /** * 检查正则表达式是否有效 * * @param pattern - 正则表达式模式 * @param flags - 标志 * @returns 是否有效 */ export declare function isValidRegex(pattern: string, flags?: RegexFlags): boolean;