C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: You can access the Regex by its identifier and call methods such as Match, Matches and IsMatch on it.
RegexNext: This program finds the first word starting with a capital R in the input string.
C# program that uses static Regex instance
using System;
using System.Text.RegularExpressions;
class Program
{
static Regex _rWord = new Regex(@"R\w*");
static void Main()
{
// Use the input string.
// ... Then try to match the first word starting with capital R.
string value = "This is a simple /string/ for Regex.";
Match match = _rWord.Match(value);
Console.WriteLine(match.Value);
}
}
Output
Regex
Review: Regular expressions are not typically the ideal solution for performance concerns.
But: They can be greatly enhanced with careful considerations of their allocation patterns, as with the static modifier.
Static