liveBook · Manning

Regular expression

As explained in .NET in Action, Second Edition

A regular expression is a pattern language for matching and processing text according to specified character sequences.

A regular expression lets a command-line file search match text in each line using a pattern instead of string.Contains. In .NET, use Regex from System.Text.RegularExpressions; pass RegexOptions.IgnoreCase when case-insensitive matching is needed. section 4.1.5 section 2.4

Listing 2.8 namespace after using
using System.Text.RegularExpressions;      #1
  
namespace System.Text;
  
public static class Bar
{
  public static readonly Regex Letters = new Regex(@"[a-z]+");
}

This listing constructs a Regex from the pattern [a-z]+. section 2.4

How .NET in Action, Second Edition covers it

How deep it goes
Identifies the .NET Regex class and IgnoreCase option, but does not explain pattern syntax or matching internals.
Examples
Uses [a-z]+ as a Regex pattern and recommends IgnoreCase for command-line searching.
What it assumes
Assumes an existing FindText search that reads lines and uses string.Contains, while introducing Regex as its replacement.
What you can do after
Apply .NET Regex to search file lines using regular expressions and IgnoreCase.
How it connects
Connects regular-expression search with command-line options, string.Contains, and .NET namespaces.

Also explained in

Compare how 27 books explain regular expression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.