Finding Numbers in Text

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell


Regular Expressions are a great help in identifying and extracting data from text. Here's an example that finds and extracts a number that ends with a comma:

PS> $text = "I am looking for a number like this 67868683468932689223479, that is delimited by a comma."
PS> $pattern = '(\d*),'

PS> if ($text -match $pattern) { $matches[1] } else { Write-Warning "Not found" }

Twitter This Tip! ReTweet this Tip!

Posted Apr 11 2012, 06:00 AM by ps1
Copyright 2012 All rights reserved.