1

In using the split operator, as:

**********************
PowerShell transcript start
Start time: 20210719105630
Username: gondor\nicholas
RunAs User: gondor\nicholas
Configuration Name: 
Machine: gondor (Unix 5.8.0.59)
Host Application: /snap/powershell/160/opt/powershell/pwsh.dll
Process ID: 16273
PSVersion: 7.1.3
PSEdition: Core
GitCommitId: 7.1.3
OS: Linux 5.8.0-59-generic #66-Ubuntu SMP Thu Jun 17 00:46:01 UTC 2021
Platform: Unix
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0, 6.1.0, 6.2.0, 7.0.0, 7.1.3
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
WSManStackVersion: 3.0
**********************
Transcript started, output file is strings.txt
PS /home/nicholas/power_shell> $string = "b1i9r8t7h"  
PS /home/nicholas/power_shell> $array = $string -split "\d"
PS /home/nicholas/power_shell> $array
b
i
r
t
h
PS /home/nicholas/power_shell> $array = $string -split "\D"
PS /home/nicholas/power_shell> $array

1
9
8
7

PS /home/nicholas/power_shell> $array = $string.split("\D")
PS /home/nicholas/power_shell> $array
b1i9r8t7h
PS /home/nicholas/power_shell> $array = $string.split("\d")
PS /home/nicholas/power_shell> $array
b1i9r8t7h
PS /home/nicholas/power_shell> Stop-Transcript
**********************
PowerShell transcript end
End time: 20210719105811
**********************

what is the result of using the dot operator above? Does it do anything? Nothing? Seems it should do something or return an error.

How is the function distinguished from the operator?

see also:

https://www.sqlshack.com/powershell-split-a-string-into-an-array/

https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-5.0

https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.split?view=net-5.0


On a side note, how are the help files for the operator and the function accessed from the REPL console?

  • 2
    The `.Split(..)` string method will split on a delimiter it doesn't work on regular expressions such as `\D` or `\d`. The `-split` operator on the other hand will allow you to split using `regex`, similar to `[regex]::Split(..)`. `[regex]::Split('b1i9r8t7h','\D')` and `'b1i9r8t7h' -split '\D'` will give you the results you expect. – Santiago Squarzon Jul 19 '21 at 19:21
  • 1
    @SantiagoSquarzon this should be an answer. To see more about the operator, check out `about_split`: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_split?view=powershell-7.1 – Cpt.Whale Jul 19 '21 at 19:59
  • 1
    @Cpt.Whale I know, I didn't post it as answer because of OP's last question "_how are the help files for the operator and the function accessed from the REPL console_" which I'm not sure how to answer but if OP considers I can post my comment as an answer I will do so. – Santiago Squarzon Jul 19 '21 at 20:02
  • I added the help file links, but, yes @SantiagoSquarzon the question is how are these things differentiated. – Nicholas Saunders Jul 19 '21 at 21:43
  • I hope [this answer](https://stackoverflow.com/a/41905031/45375) to the linked duplicates answers all questions. – mklement0 Jul 19 '21 at 22:20

1 Answers1

0

Help files say:

Remarks

The Regex.Split methods are similar to the String.Split(Char[]) method, except that Regex.Split splits the string at a delimiter determined by a regular expression instead of a set of characters.

which is all fine and good.

Would welcome a more in depth answer.