HOME > System software > Regex Match C#: How To Check A Match

Regex match C#: How to check a match

When you program, sooner or later you can't avoid regular expressions or regex. C# provides you with special methods for this purpose, which make it easier for you to deal with the expressions. To access the various class, you need the corresponding namespace "System.Text.RegularExpressions".

How to use C#'s regex match method

If you work with regular expressions in C#, it is worth using the classes provided by the .NET Framework. For this, it is necessary to include the namespace "System.Text.RegularExpressions" with using. Among numerous other methods, there is also the Regex.Match() method, which uses a regex to check for a match.
  1. The Match method comes in several flavors. You can read about these in the documentation with the appropriate descriptions.
  2. For example, a use case for this method is when you want to check whether there is a match and then want the corresponding value to be output.
  3. For this, you must first create a regex with regex regex = new Regex(). Als Argument übergeben Sie hier Ihren regulären Ausdruck.
  4. Anschließend erzeugen Sie ein Match mit Match match = regex.Match(). Nun übergeben Sie als Argument den String, den Sie überprüfen möchten.
  5. Mithilfe von match.Success erhalten Sie einen boolean Wert, der Ihnen „true“ zurückgibt, wenn es eine Übereinstimmung gibt und „false“, wenn nicht.

By Melda Nienhuis

Connecting Samsung Galaxy S10 to PC :: Scanning business cards - how to do it
USEFUL LINKS