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 PowerShell: Automating Administrative Tasks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.