regex class : Match(string) method

Description

Gets a first substring in the argument which matches with the regular expression.

Syntax

regexInstance.Match(string source)

Arguments

ClassNameDescription
stringsourceA string which is searched.

Return value

ClassDescription
stringA first substring which matches with the regular expression.

Sample code

1:

regex pattern = new regex("(a+)");

2:

string firstMatch = pattern.Match("aaabbbaaccc"); // "aaa".

Notes

It's a wrapper of the System.Text.RegularExpressions.Regex.Match(String) method.

If no match is found, return value is empty string.

Links for reference

Copyright © Cooker All rights reserved.