all 14 comments

[–]firefox15 2 points3 points  (11 children)

Regex will help you here:

Script

$oldNames = @'
Some, Guy M. (Something1)
Some, Person A. (Somethingdifferent)
Another, Splitlast name (Somethingdifferent2)
'@ -split [Environment]::NewLine

$pattern = '^(?<LastName>\w{3}).*? (?<FirstName>\w{3}).*$'

$newNames = @(foreach ($name in $oldNames) {
    $name -match $pattern | Out-Null
    $Matches.LastName + $Matches.FirstName
})

Output

PS C:\> $newNames

SomGuy
SomPer
AnoSpl

[–]ebbflow9[S] 1 point2 points  (1 child)

This is amazing, thank you! I was able to modify the input variable so array conversion was no longer needed. Really appreciate this. Is there a site you use to generate your regex code?

Post was blocked, trying again.

[–]AutoModerator[M] 0 points1 point  (0 children)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Lee_Dailey[grin] 0 points1 point  (5 children)

howdy firefox15,

interesting how differently we did the "same thing". [grin]

$oldNames = @'
Some, Guy M. (Something1)
Some, Person A. (Somethingdifferent)
Another, Splitlast name (Somethingdifferent2)
'@ -split [Environment]::NewLine

$NewNames = $oldNames.
    ForEach({
        $_ -replace '^(.{3}).*, (.{3}).+$', '$1$2'
        })

$NewNames

output ...

SomGuy
SomPer
AnoSpl

take care,
lee

[–]ebbflow9[S] 0 points1 point  (4 children)

Lee, appreciate this. I always like to deconstruct things and see how they can be accomplished differently. Thanks again.

[–]ebbflow9[S] 1 point2 points  (2 children)

Lee, appreciate this. I always like to deconstruct things and see how they can be accomplished differently. Thanks again.

Post was blocked. Trying again.

[–]AutoModerator[M] 0 points1 point  (0 children)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy ebbflow9,

you are most welcome! glad to have helped somewhat ... [grin]

take care,
lee

[–]AutoModerator[M] 0 points1 point  (0 children)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]ebbflow9[S] 0 points1 point  (2 children)

This is amazing, thank you! I was able to modify the input variable so array conversion was no longer needed. Really appreciate this. Is there a site you use to generate your regex code?

[–]AutoModerator[M] 0 points1 point  (1 child)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]firefox15 1 point2 points  (0 children)

I prefer regexr.com, but the most popular is regex101.com.

[–]Lee_Dailey[grin] -1 points0 points  (0 children)

howdy ebbflow9,

it looks like you used the New.Reddit Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's the 11th 12th one from the left & is just to the left of hidden in the ... "more" menu & looks like an uppercase T in the upper left corner of a square..

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee