liveBook · Manning

End anchor

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

An end-of-string anchor is a regular-expression assertion that requires a match to occur at the end of the input string.

An end anchor requires a regular-expression match to reach the end of the input string. In a pattern such as WIN[\W\w]+TM[234][0-9]\$, the final backslash makes the dollar sign literal; without it, $ would act as the end anchor. section 21.4

Find selected computer-account logons

Filter Security events for ID 4624, then match account names beginning with WIN and ending in TM20$ through TM40$. The pattern is useful when the account name must finish at a specific boundary rather than merely contain the same characters. section 21.4

PS C:\> get-eventlog -LogName security | where { $_.eventid -eq 4624 } | 
select -ExpandProperty message | select-string -pattern 
"WIN[\W\w]+TM[234][0-9]\$"

Run the PowerShell pipeline to apply the pattern to expanded Security event messages. section 21.4

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Defines end-of-string matching and contrasts it with an escaped literal dollar sign, without discussing regex-engine internals.
Examples
Uses event ID 4624 and computer-account names ranging from TM20$ through TM40$.
What you can do after
Apply it via PowerShell Select-String to constrain regex matches to the end of event-message text.
How it connects
Connects regular expressions with Select-String, PowerShell pipelines, and Windows event logs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.