Regex 语法
Regex 语法
功能
说明 BT 正则表达式的基础写法:通过 regex(pattern, flags) 创建 Regex 对象,再调用 test、match、replace,或传给 String.search/String.match/String.replace。
语法
regex(pattern, flags)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| pattern | String | 否 | '' | 正则主体。 |
| flags | String | 否 | '' | 标志字符串。 |
返回值
| 类型 | 说明 |
|---|---|
| Regex | 返回 Regex 对象。 |
示例
rule = regex('^BT$', '') result = rule.test('BT') // 输出:true print result
注意事项
- 底层使用 Rust regex 引擎。
- 正则编译失败时会抛出中文错误。