Method regexp.Match(+ 4 overloads)
Overload
Returns true
if string s matches this regular expression.
Gets match info as RXMatch.
public bool Match(string s, out RXMatch result, Range? range = null, RXMatchFlags matchFlags = 0)
Parameters
s (string)
Subject string.
If |
result (RXMatch)
Receives match info. |
range (Range?)
Start and end offsets in the subject string. If |
matchFlags (RXMatchFlags)
Options. The same options also can be set in regexp constructor's flags. Constructor's flags and matchFlags are added, which means that matchFlags cannot unset flags set by constructor. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
AuException
The PCRE API function pcre2_match failed. Unlikely. |
Remarks
This function is similar to System.Text.RegularExpressions.Regex.Match.
Examples
var s = "one two22 three333 four";
var x = new regexp(@"\b(\w+?)(\d+)\b");
if(x.Match(s, out var m)) print.it(m.Value, m[1].Value, m[2].Value);
Overload(next)
Returns true
if string s matches this regular expression.
Gets whole match or some group, as RXGroup (index, length, value).
public bool Match(string s, int group, out RXGroup result, Range? range = null, RXMatchFlags matchFlags = 0)
Parameters
s (string)
Subject string.
If |
group (int)
Group number (1-based index) of result. If 0 - whole match. See also regexp.GetGroupNumberOf. |
result (RXGroup)
Receives match info. |
range (Range?)
Start and end offsets in the subject string. If |
matchFlags (RXMatchFlags)
Options. The same options also can be set in regexp constructor's flags. Constructor's flags and matchFlags are added, which means that matchFlags cannot unset flags set by constructor. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid group or range. |
AuException
The PCRE API function pcre2_match failed. Unlikely. |
Remarks
This function is a simplified version of Match(string, out RXMatch, Range?, RXMatchFlags).
Examples
var s = "one two22 three333 four";
var x = new regexp(@"\b(\w+?)(\d+)\b");
if(x.Match(s, 0, out RXGroup g)) print.it(g.Value, g.Start);
Overload(next)
Returns true
if string s matches this regular expression.
Gets whole match or some group, as string.
public bool Match(string s, int group, out string result, Range? range = null, RXMatchFlags matchFlags = 0)
Parameters
s (string)
Subject string.
If |
group (int)
Group number (1-based index) of result. If 0 - whole match. See also regexp.GetGroupNumberOf. |
result (string)
Receives the match value. |
range (Range?)
Start and end offsets in the subject string. If |
matchFlags (RXMatchFlags)
Options. The same options also can be set in regexp constructor's flags. Constructor's flags and matchFlags are added, which means that matchFlags cannot unset flags set by constructor. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid group or range. |
AuException
The PCRE API function pcre2_match failed. Unlikely. |
Remarks
This function is a simplified version of Match(string, out RXMatch, Range?, RXMatchFlags).
Examples
var s = "one two22 three333 four";
var x = new regexp(@"\b(\w+?)(\d+)\b");
if(x.Match(s, 0, out string v)) print.it(v);
Overload(next)
Returns true
if string span s matches this regular expression.
Gets whole match or some group, as StartEnd.
public bool Match(ReadOnlySpan<char> s, int group, out StartEnd result, Range? range = null, RXMatchFlags matchFlags = 0)
Parameters
s (ReadOnlySpan<char>)
Subject string.
If |
group (int)
Group number (1-based index) of result. If 0 - whole match. See also regexp.GetGroupNumberOf. |
result (StartEnd)
Receives match info. |
range (Range?)
Start and end offsets in the subject string. If |
matchFlags (RXMatchFlags)
Options. The same options also can be set in regexp constructor's flags. Constructor's flags and matchFlags are added, which means that matchFlags cannot unset flags set by constructor. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid group or range. |
AuException
The PCRE API function pcre2_match failed. Unlikely. |
Remarks
This function is a simplified version of Match(string, out RXMatch, Range?, RXMatchFlags).
Examples
var s = "one two22 three333 four";
var x = new regexp(@"\b(\w+?)(\d+)\b");
if(x.Match(s, 0, out RXGroup g)) print.it(g.Value, g.Start);
Overload(top)
Returns true
if string span s matches this regular expression.
Writes match info to caller-allocated memory (array, stackalloc array, etc).
public bool Match(ReadOnlySpan<char> s, Span<StartEnd> result, Range? range = null, RXMatchFlags matchFlags = 0)
Parameters
s (ReadOnlySpan<char>)
Subject string.
If |
result (Span<StartEnd>)
Receives match info: main match in |
range (Range?)
Start and end offsets in the subject string. If |
matchFlags (RXMatchFlags)
Options. The same options also can be set in regexp constructor's flags. Constructor's flags and matchFlags are added, which means that matchFlags cannot unset flags set by constructor. |
Returns
Exceptions
ArgumentOutOfRangeException
Invalid range. |
AuException
The PCRE API function pcre2_match failed. Unlikely. |
ArgumentException
result array too short. |