Windows PowerShell

PowerShell Tip: String Manipulation using Regular Expression


  • Regular Expression is very Powerful and best way to play with strings.
  • Using REGEX in PowerShell is best way to query log files, pattern matching etc.., however we should use it as applicable.

Example Code

#Given Name : Chendrayan Venkatesan
#Required Output: Venkatesan , Chendrayan
"Chendrayan Venkatesan" -replace "([a-z]+)\s([a-z]+)" ,'$2, $1' 

#Given Name : Chendrayan12345 Venkatesan
#Required Output: Venkatesan, Chendrayan
'Chendrayan12345 Venkatesan' -replace "\d+" -replace "([a-z]+)\s([a-z]+)" ,'$2, $1'


Leave a Reply

Your email address will not be published. Required fields are marked *