Removing Characters at the Beginning of Text

by Jan 11, 2012

To remove text at the beginning of a sentence rather than somewhere inside the sentence, use the operator -replace and the anchor '^'. Check out the difference:

PS> 'PC101 is the PC we are overhauling' -replace 'PC',''
101 is the  we are overhauling
PS> 'PC101 is the PC we are overhauling' -replace '^PC',''
101 is the PC we are overhauling

Twitter This Tip!
ReTweet this Tip!