编译正则表达式并返回 Regex 对象。
regex(pattern, flags)
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| pattern | String | 否 | '' | 正则表达式文本。 |
| flags | String | 否 | '' | 标志;i 忽略大小写,m 多行,s 点号匹配换行,g 供 replace 全局替换使用。 |
| 类型 | 说明 |
|---|---|
| Regex | 返回可调用 test、match、replace 的正则对象。 |
rule = regex('BT', 'i') result = rule.test('bt') // 输出:true print result