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?

5
  • 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. Commented Jul 19, 2021 at 19:21
  • 1
    @SantiagoSquarzon this should be an answer. To see more about the operator, check out about_split: learn.microsoft.com/en-us/powershell/module/… Commented Jul 19, 2021 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. Commented Jul 19, 2021 at 20:02
  • I added the help file links, but, yes @SantiagoSquarzon the question is how are these things differentiated. Commented Jul 19, 2021 at 21:43
  • I hope this answer to the linked duplicates answers all questions. Commented Jul 19, 2021 at 22:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.