Next This program finds the first word starting with a capital R in the input string.
Tip The biggest benefit of static Regex instances is that they will not likely be created more than once.
Info Your regular expression can be shared between many different methods on the type. This will improve performance.
C# program that uses static Regex instance
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);
Performance. Static regular expressions show a performance advantage. Static fields do not have an instance expression, so resolving the location of their memory storage is slightly faster.
Performance, continued. Regular expressions are not an ideal solution for performance. They can be sped up with considerations of their allocation patterns, as with the static modifier.