Regular expression anchors

Anchors are used to tell the regular expression where to start and end the evaluation of a string. The most common anchors evaluate the characters at the beginning or the end of a string. This allows you to validate that the string starts and/or ends with a digit, symbol, or letter character. The most common anchors are:

  • ^ and \A: The ^ and \A anchor characters indicates matching at the start of a string for evaluation. If you want to ensure that a certain pattern is matched at the beginning, you will use ^ or \A. The \A syntax is symbolic of the first character in the alphabet which is a. This is why regular expressions use this character to designate the evaluation from the start of a string.
  • $ and \Z: The $ and \Z

Get Mastering Windows PowerShell Scripting now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.