Example input is: 0009911000
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.
http://quickbytesstuff.blogspot.sg/2014/09/how-to-recite-rosary.html
$Input_Number = '0009911000'
#[1] = tells regex to match on the right or look forward
$xtotal=[regex]::Matches($Input_Number,'0+')[1].Value.Length
$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)
$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:
Output will be something like this:
Groups : {0000}
Success : True
Captures : {0000}
Index : 0
Length : 4
Value : 0000
Groups : {000}
Success : True
Captures : {000}
Index : 8
Length : 3
Value : 000
Groups : {0}
Success : True
Captures : {0}
Index : 12
Length : 1
Value : 0
Image output from PowerShell ISE:
Regex is not easy it might take a while to digest and depends
on what data being processed, the regex pattern used to match the data will be
different. It will be not a one size fits all solution. Mileage will always
vary when working with regex, if your task requires a lot of regex then practice
is a must.
Regular Expression quick reference from Microsoft: https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
================================
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
Heaven's Dew Fall Prayer app for Android :
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment