# ansi-regex **Repository Path**: ArkTSCentralRepository/ansi-regex ## Basic Information - **Project Name**: ansi-regex - **Description**: ansi-regex 是一个用于匹配 ANSI 转义码的正则表达式工具,支持选项来控制是否只匹配第一个转义码。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-21 - **Last Updated**: 2024-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ansi-regex 基于[ansi-regex](https://www.npmjs.com/package/ansi-regex)原库6.1.0版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ## Install ```sh ohpm install ansi-regex ``` ## Usage ```typescript import ansiRegex from 'ansi-regex'; ansiRegex().test('\u001B[4mcake\u001B[0m'); //=> true ansiRegex().test('cake'); //=> false '\u001B[4mcake\u001B[0m'.match(ansiRegex()); //=> ['\u001B[4m', '\u001B[0m'] '\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})); //=> ['\u001B[4m'] '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex()); //=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007'] ``` ## API ### ansiRegex(options?) Returns a regex for matching ANSI escape codes. #### options Type: `object` ##### onlyFirst Type: `boolean`\ Default: `false` *(Matches any ANSI escape codes in a string)* Match only the first ANSI escape.