Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Need some regex help

$
0
0

We have daily queries from our user databases that we use for terminating user access. Normally, we take this data and paste it into Excel and save it to CSV for later use. I’m trying to automate the process the best I can. I have it about 99% done but there’s some stragglers that I’m having a hard time figuring out.

The normal lines have a minimum of 2 spaces between each property. So an example would be:

Server Lastname, Firstname username Role LastLogon PS01 Smith, John jsmith Admin 7/12/2013 14:36 

I’m using ($Data -match “^[a-z][a-z]d{1,3}”) -replace “(ss+)”,”;” which is working great, except there’s a few gotchas from the output: If the user has a VERY long name, it will use all but one space. So if I search for 2+ spaces, my output will have some multiple entries under the same property.

Server Name Username Role LastLogon PS01 LongLastName, LongFirstName longlastnameusername Administrators 2/2/2015 15:53 

I’m pretty much looking for something that can consistently find the actual whitespace in-between each property and replace it with a ‘;’.

A few constants I know:

Lastname, Firstname will always have the comma (but may have 3+ names and letters and other symbols (I.E. Lastname, LegalName (NickName))

Username will always be lowercase

Role will never have a number

LastLogon may or may not have data

submitted by /u/Llamathrust
[link] [comments]

The post Need some regex help appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles