Example input is: 0009911000 $Input_Number = '0009911000' #[1] = tells regex to match on the right or look forward $xtotal=[regex]::Matches($Input_Number,'0+')[1].Value.Length #[0] = tells regex to match on the left or look backward $ytotal=[regex]::Matches($Input_Number,'0+')[0].Value.Length #Matches($Number,'0+') means #Matches($input, $pattern) Write-Output $xtotal Write-Output $ytotal Image output from PowerShell ISE: Above code works or matches if input is something like this: “0009911000” There are zeroes on the left and right and in between are any numbers or characters. For input like this: 0000991100010 in which zeroes are in different position of the string the below code will work. $Input_Number = '0000991100010' $xytotal=[regex]::Matches($Input_Number,'[0]*[0]*[0]+') Write-Output $xytotal Output will be something like this: Groups : {0000} Success : True Captures : {...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.