正则对象模型

当前位置:首页>正则>正则对象模型

正则对象模型

# pcre2/deelx RegExp对象模型


本文档按层级列出COM 对象成员,并对 `RegExp`、`RegExp2`、`VBScript.RegExp` 做并排对照。


## 1. 顶层对象


- `loquat.RegExp` → `IRegExp`

- `loquat.RegExp2` → `IRegExp2`

- `VBScript.RegExp`


## 2. RegExp / RegExp2 / VBScript.RegExp 成员对照

### 2.1 属性(同名/同语义同一行)


| 语义 | RegExp (`IRegExp`) | RegExp2 (`IRegExp2`) | VBScript.RegExp |

|---|---|---|---|

| 模式 | `Pattern` | `Pattern` | `Pattern` |

| 全局 | `Global` | `Global` | `Global` |

| 忽略大小写 | `IgnoreCase` | `IgnoreCase` | `IgnoreCase` |

| 多行 | `Multiline` | `MultiLine` | `Multiline` |

| 单行 | - | `SingleLine`(只读) | - |

| 从右到左 | - | `RightToLeft`(只读) | - |

| 扩展模式 | `Extended` | `Extended`(只读) | - |

| UTF | `UTF` | - | - |

| DotAll | `DotAll` | - | - |

| Ungreedy | `Ungreedy` | - | - |

| AutoJIT | `AutoJIT` | - | - |

| UseDFA | `UseDFA` | - | - |

| OptionsCompile | `OptionsCompile`(只读) | - | - |

| OptionsMatch | `OptionsMatch`(只读) | - | - |

| OptionsReplace | `OptionsReplace`(只读) | - | - |

| MatchLimit | `MatchLimit` | - | - |

| RecursionLimit | `RecursionLimit` | - | - |

| OffsetLimit | `OffsetLimit` | - | - |

| IsJITCompiled | `IsJITCompiled`(只读) | - | - |

| LastError | `LastError`(只读) | - | - |

| LastErrorCode | `LastErrorCode`(只读) | - | - |

| CompileTime | `CompileTime`(只读) | - | - |

| LastMatchTime | `LastMatchTime`(只读) | - | - |

| IsCompiled | `IsCompiled`(只读) | - | - |

| EnableCallout | `EnableCallout` | - | - |

| AutoCallout | `AutoCallout` | - | - |

| CalloutStats | `CalloutStats`(只读) | - | - |

| 自引用 | `Me` / `Self` | - | - |


### 2.2 方法(同名/同语义同一行)


| 语义 | RegExp (`IRegExp`) | RegExp2 (`IRegExp2`) | VBScript.RegExp |

|---|---|---|---|

| 测试 | `Test(SourceString)` | `Test(SourceString)` | `Test(SourceString)` |

| 执行 | `Execute(SourceString)` | `Execute(SourceString)` | `Execute(SourceString)` |

| 替换 | `Replace(SourceString, ReplaceString)` | `Replace(SourceString, ReplaceString)` | `Replace(SourceString, ReplaceString)` |

| 分割 | `Split(SourceString, Limit?)` | `Split(SourceString, Limit?)` | - |

| 校验模式 | - | `Validate(pattern, pIsValid, pErrorMsg)` | - |

| 获取命名组 | `GetNamedGroups()` | - | - |

| 获取捕获组数 | `GetCaptureCount()` | - | - |

| 编译 JIT | `CompileJIT()` | - | - |

| 设置回调 | `SetCalloutHandler(FunctionPtr, UserData?)` | - | - |

| 清理回调 | `ClearCalloutHandler()` | - | - |

| 枚举 Callout | `EnumerateCallouts()` | - | - |

| 重置统计 | `ResetCalloutStats()` | - | - |

| 序列化 | `Serialize()` | - | - |

| 反序列化 | `Deserialize(bytes)` | - | - |


## 3. PCRE2 主线对象层级(RegExp)


- `RegExp (IRegExp)`

  - `Execute()` → `MatchCollection (IMatchCollection)`

  - `OptionsCompile` → `OptionsCompile (IOptionsCompile)`

  - `OptionsMatch` → `OptionsMatch (IOptionsMatch)`

  - `OptionsReplace` → `OptionsReplace (IOptionsReplace)`

  - `CalloutStats` → `CalloutStats (ICalloutStats)`

  - `EnumerateCallouts()` → `CalloutEnumCollection (ICalloutEnumCollection)`


- `MatchCollection (IMatchCollection)`

  - 属性:`Count`, `Item(index)`, `_NewEnum`, `Me`, `Self`

  - 方法:`ToArray()`, `ToJSON()`

  - 下级:`Item(index)` → `Match (IMatch)`


- `Match (IMatch)`

  - 属性:`Value`, `FirstIndex`, `Length`, `LastIndex`, `GroupCount`, `MatchNumber`, `SubMatches`, `Me`, `Self`

  - 方法:`ToJSON()`

  - 下级:`SubMatches` → `SubMatches (ISubMatches)`


- `SubMatches (ISubMatches)`

  - 属性:`Count`, `Item(NameOrIndex)`, `_NewEnum`, `Me`, `Self`

  - 方法:`GetValue()`, `Exists()`, `GetNames()`, `ToArray()`, `ToJSON()`

  - 下级:`Item(...)` → `SubMatch (ISubMatch)`


- `SubMatch (ISubMatch)`

  - 属性:`Value`, `FirstIndex`, `LastIndex`, `Length`, `Name`, `Number`, `IsMatched`, `Me`, `Self`

  - 方法:`ToJSON()`


## 4. deelx 主线对象层级(RegExp2)


- `RegExp2 (IRegExp2)`

  - `Execute()` → `MatchCollection2 (IMatchCollection2)`


- `MatchCollection2 (IMatchCollection2)`

  - 属性:`Count`, `Item(index)`, `_NewEnum`, `Input`

  - 方法:`ToArray()`, `ToJSON()`

  - 下级:`Item(index)` → `Match2 (IMatch2)`


- `Match2 (IMatch2)`

  - 属性:`Value`, `FirstIndex`, `Length`, `SubMatches`, `Index`, `Input`

  - 方法:`ToJSON()`

  - 下级:`SubMatches` → `SubMatches2 (ISubMatches2)`


- `SubMatches2 (ISubMatches2)`

  - 属性:`Count`, `Item(KeyOrIndex)`, `_NewEnum`

  - 方法:`GetValue()`, `Exists()`, `GetNames()`, `ToArray()`, `ToJSON()`, `GetNamedValue()`

  - 下级:`Item(...)` → `SubMatch2 (ISubMatch2)`


- `SubMatch2 (ISubMatch2)`

  - 属性:`Value`(可读写), `Index`, `Length`, `Name`

  - 方法:`ToJSON()`


## 5. 扩展对象层级(RegExp)


- `OptionsCompile (IOptionsCompile)`

  - 属性:`Anchored`, `DollarEndOnly`, `NoAutoCapture`, `DupNames`, `ExtendedMore`, `Literal`, `RawValue`

  - 方法:`Reset()`, `ToString()`


- `OptionsMatch (IOptionsMatch)`

  - 属性:`NotBOL`, `NotEOL`, `NotEmpty`, `NotEmptyAtStart`, `NoUTFCheck`, `RawValue`

  - 方法:`Reset()`, `ToString()`


- `OptionsReplace (IOptionsReplace)`

  - 属性:`Literal`, `Extended`, `UnknownUnset`, `UnsetEmpty`, `RawValue`

  - 方法:`Reset()`, `ToString()`


- `CalloutStats (ICalloutStats)`

  - 属性:`CalloutCount`, `BacktrackCount`, `StartMatchCount`, `MaxDepth`, `TotalTime`

  - 方法:`Reset()`, `ToString()`


- `CalloutEnumCollection (ICalloutEnumCollection)`

  - 属性:`Count`, `Item(index)`, `_NewEnum`

  - 方法:`ToArray()`, `ToJSON()`

  - 下级:`Item(index)` → `CalloutEnum (ICalloutEnum)`


- `CalloutEnum (ICalloutEnum)`

  - 属性:`PatternPosition`, `NextItemLength`, `CalloutNumber`, `CalloutString`, `CalloutStringOffset`, `CalloutStringLength`

  - 方法:`ToJSON()`


- `CalloutInfo (ICalloutInfo)`

  - 基础:`Version`, `CalloutNumber`, `CalloutString`, `CalloutStringOffset`, `CalloutStringLength`

  - 状态:`Subject`, `SubjectLength`, `CurrentPosition`, `StartMatch`, `PatternPosition`, `NextItemLength`

  - 捕获:`CaptureTop`, `CaptureLast`, `OffsetVector`

  - 标志:`CalloutFlags`, `IsStartMatch`, `IsBacktrack`, `Mark`

  - 方法:`GetCaptureValue(GroupNumber)`, `ToJSON()`