Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

RegEx Tip, Replace String set number of times

$
0
0

All

Here is another quick tip, last one Smile

lets say you have a string "AA124BB55HH657AAR555" now you want to replace the numbers (but only where there are 3 numbers together, not just 2) with say a # symbol, but you only want to replace the first two instances of 3 numbers. You will see this string contains three sets of three numbers

[regex]'\d{3}').Replace('AA124BB55HH657AAR555','#',2)

AA#BB55HH#AAR555

Hope this is helpful

Ernie


Viewing all articles
Browse latest Browse all 6937

Trending Articles