Regex modifier
Regex modifier
Function
Description of the flags supported by regex(pattern, flags). The current source code uses i, m, s to participate in compilation, and g is used by replace to determine whether to replace globally.
Syntax
regex(pattern, flags)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| pattern | String | No | '' | Regular body. |
| flags | String | No | '' | i ignores case; m multi-line; s dot matches newline; g is used for replace global replacement. |
Return value
| Type | Description |
|---|---|
| Regex | Returns a Regex object. |
Example
rule = regex('bt', 'i') result = rule.test('BT') // Output: true print result
Notes
- g does not participate in regex compilation, and only controls the number of substitutions when Regex.replace and String.replace receive Regex.