Class RXMatch
Regular expression match info. Used with regexp class functions and String extension methods like ExtString.RxMatch.
public class RXMatch
Remarks
Contains info about a regular expression match found in the subject string: index, length, substring, etc.
Also contains an array of group matches, as RXGroup. Groups are regular expression parts enclosed in (), except (?...).
Group matches can be accessed like array elements. Group 0 is whole match. Group 1 is the first group. See examples.
Examples
var s = "ab cd-45-ef gh";
if(s.RxMatch(@"\b([a-z]+)-(\d+)\b", out RXMatch m))
print.it(
m.GroupCountPlusOne, //3 (whole match and 2 groups)
m.Start, //3, same as m[0].Index
m.Value, //"cd-45-ef", same as m[0].Value
m[1].Start, //3
m[1].Value, //"cd"
m[2].Start, //6
m[2].Value //"45"
);
A group in the subject string may not exist even if whole match found. Then its Exists property is false, Index -1, Length 0, Value null.
var s = "ab cd--ef gh";
if(s.RxMatch(@"\b([a-z]+)-(\d+)?-([a-z]+)\b", out RXMatch m))
print.it(
m.GroupCountPlusOne, //4 (whole match and 3 groups)
m[2].Exists, //false
m[2].Start, //-1
m[2].Length, //0
m[2].Value //null
);
Namespace: Au.Types
Assembly: Au.dll
Properties
| Name | Description |
|---|---|
| End | Gets end offset of the match in the subject string (RXMatch.Start + RXMatch.Length). The same as that of group 0 (RXGroup.End). |
| Exists | Gets the return value of the regexp.Match call. |
| GroupCountPlusOne | Gets the number of groups in the regular expression, + 1 for the whole match. |
| IsPartial | Returns |
| this[int] | Gets group info. Index 0 is whole match. Index 1 is the first group. |
| this[string] | Gets group info of a named group. |
| Length | Gets length of the match in the subject string. The same as that of group 0 (RXGroup.Length). |
| Mark | Gets the name of a found mark, or |
| Span | Gets span of the subject string from RXMatch.Start to RXMatch.End. The same as that of group 0 (RXGroup.Span). |
| Start | Gets start offset of the match in the subject string. The same as that of group 0 (RXGroup.Start). |
| StartNoK | Gets start offset of whole match regardless of |
| Subject | Gets the subject string in which this match was found. |
| Value | Gets substring of the subject string from RXMatch.Start to RXMatch.End. The same as that of group 0 (RXGroup.Value). |
Methods
| Name | Description |
|---|---|
| ExpandReplacement(string) | Returns expanded version of the specified replacement pattern. |
| GroupNumberFromName(string) | Finds a named group and returns its 1-based index. Returns -1 if not found. |
| GroupNumberFromName(string, out bool) | Finds a named group and returns its 1-based index. Returns -1 if not found. |
| ToString() | Returns RXGroup.ToString of group 0. |