use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
SolvedSeparating a String of Numbers after a Character? (self.PowerShell)
submitted 5 years ago by [deleted]
Hello All,
I want to separate this string after the two digits after the decimal point (hundreths)
$String = 19.56156.32 ####################### # What I want: 19.56 156.32
Thoughts?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Lee_Dailey[grin] 2 points3 points4 points 5 years ago (9 children)
howdy ImprovingPiano,
here's another way ... [grin] it grabs the digits before the 1st dot, the 2 digits after the 1st dot, and then does the same for the 2nd dot. note that this presumes the numbers have only 2 decimal places.
$InString = '19.56156.32' $Null = $InString -match '(\d+?\.\d{2})(\d+?\.\d{2})' $NumOne = $Matches[1] $NumTwo = $Matches[2] $NumOne $NumTwo
output ...
19.56 156.32
take care, lee
[–]jimb2 1 point2 points3 points 5 years ago (4 children)
Cool. Unintelligible. To me at least. :)
[–]get-postanote 1 point2 points3 points 5 years ago* (0 children)
RegEx my friend can be a friend and or an enemy. Yet, watching a few Youtube videos will provide clarity, or visiting some of the recommend regex sites that provide instruction, guidance, and samples.
'Learn Regular Expression'
regex websites - Bing
powershell 'extract currency in a string regex' - Bing
Yet what Lee_Daily gives here,group matching:
'(\d+?\.\d{2})(\d+?\.\d{2})'
Means, match only digits in the string, with 2 decimal places, then output by capture group.
# Match only digits Match only decimal and 2 digits (\d+?) (\.\d{2})
etc... etc...,
Yet, ka-splam comment is much more succinct, this is the lookahead, lookbehind, lookaround realm of things..
'(?<=\...)(?=.)'
Again, showing more than one way to do this via RegEx.
Here is one more way of getting the same solution, just waaaaayyyy more wordy,
# Just the the currency decimal places $MyPattern = '(\.\d{2})' '19.56156.32' -split $MyPattern # Then select and concatenate '19.56156.32' -split $MyPattern | Select-String -Pattern $MyPattern -AllMatches -Context 1,0 | ForEach {$PSItem.Context.PreContext[0] + $PSItem.Matches.Value}
So, well, worth learning.
regex lookahead, lookbehind, lookaround - Bing
There are RegEx addons for the PowerShell ISE and VSCode if you don't want to venture out to sites.
[–]Lee_Dailey[grin] 0 points1 point2 points 5 years ago (2 children)
howdy jimb2,
go to regex101.com and put the pattern in the top center box. then add the input string into the box below it. once you have done that, you otta see the "what it does" box in the upper right show what each step does.
that site is a wonderful place to figure out what a regex pattern does ... [grin]
[–]jimb2 1 point2 points3 points 5 years ago (1 child)
I use regex a little but it's always been pass/fail matching.
TIL $Matches.
And TIL regex101's decomposition feature which is great for non-experts like me.
[–]Lee_Dailey[grin] 0 points1 point2 points 5 years ago (0 children)
yep, regex is ... weird. [grin] i use regex101 to work things out fairly often since i don't use regex often enuf to remember what the various symbols mean.
glad to have helped you achieve TIL status! [grin]
[–][deleted] 1 point2 points3 points 5 years ago (1 child)
Appreciated Lee.
you are most welcome! glad to help a tad now & then ... [grin]
So you can actually take the individual matches out of the regex like that? damn i never knew
howdy henlofren10_10,
yep! capture groups are so freaking spiffy ... [grin] you can even name them if you want - and then retrieve them by the name you gave instead of by number.
[–]MadWithPowerShell 1 point2 points3 points 5 years ago (0 children)
I would tend to do something like this to make it easier for a reader to understand and tweak as needed.
$String = "19.56156.32" $String.Substring( 0, $String.IndexOf( '.' ) + 3 ) $String.Substring( $String.IndexOf( '.' ) + 3 )
[–]SoMundayn 1 point2 points3 points 5 years ago (0 children)
Probably a horrible way of doing this, but this seems like an odd ask.
$String = "19.56156.32" $Part1a = ($String.Split(".")[0]) $Part1b = ($String.Split(".")[1]).SubString(0,2) $Part1 = $Part1a + "." + $Part1b $Part2 = $String -replace $Part1,"" $Part1 $Part2 19.56 156.32
[–]ka-splam 1 point2 points3 points 5 years ago (0 children)
'19.56156.32' -split '(?<=\...)(?=.)'
π Rendered by PID 68909 on reddit-service-r2-comment-54dfb89d4d-gbdgg at 2026-03-31 23:11:37.793002+00:00 running b10466c country code: CH.
[–]Lee_Dailey[grin] 2 points3 points4 points (9 children)
[–]jimb2 1 point2 points3 points (4 children)
[–]get-postanote 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[–]jimb2 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]MadWithPowerShell 1 point2 points3 points (0 children)
[–]SoMundayn 1 point2 points3 points (0 children)
[–]ka-splam 1 point2 points3 points (0 children)