Basic Patterns:

  1. .: Any character except a newline.
  2. ^: Start of the line.
  3. $: End of the line.
  4. \b: Word boundary.
  5. \d: Digit (0-9).
  6. \D: Non-digit.
  7. \w: Word character (alphanumeric + underscore).
  8. \W: Non-word character.
  9. \s: Whitespace character.
  10. \S: Non-whitespace character.

Quantifiers:

  1. *: 0 or more occurrences.
  2. +: 1 or more occurrences.
  3. ?: 0 or 1 occurrence.
  4. {n}: Exactly n occurrences.
  5. {n,}: n or more occurrences.
  6. {n,m}: Between n and m occurrences.

Character Classes:

  1. [abc]: Any one of the characters a, b, or c.
  2. [a-z]: Any lowercase letter.
  3. [A-Z]: Any uppercase letter.
  4. [0-9]: Any digit.

Anchors:

  1. \bword\b: Word boundary for the word “word”.
  2. ^word: Line starts with “word”.
  3. word$: Line ends with “word”.

Grouping and Alternation:

  1. (abc): Grouping.
  2. a|b: Either a or b.

Escape Characters:

  1. : Escape character. Use it to match literal characters like . or .

Modifiers:

  1. i: Case-insensitive.
  2. m: Multi-line mode.

Quantifiers (non-greedy):

  1. *?: Match 0 or more, as few as possible.
  2. +?: Match 1 or more, as few as possible.
  3. ??: Match 0 or 1, as few as possible.
  4. {n,}?: Match at least n, as few as possible.
  5. {n,m}?: Match between n and m, as few as possible.

Common C# Regex Methods:

  1. Regex.IsMatch(input, pattern): Returns true if the input string matches the pattern.
  2. Regex.Match(input, pattern): Returns the first match.
  3. Regex.Matches(input, pattern): Returns all matches.
  4. Regex.Replace(input, pattern, replacement): Replaces matches with the specified