RegEx Match strings

by ellobo at 2013-03-01 12:45:41

I am stuck on a script I am working on. The script reads a text file and parses each line and inserts semi-colons between the columns so that I can later easily upload the results up to SQL Server. Please see my attached script. Like I said I am stuck on some name columns. I need to match on a sting of characters like show below.

Supervisor Collector
-------------------- --------------------
DEYOUNG,MR. RICHARD E MATIAS, SEAN J

Can someone help me with the code to match the name patterns in the two columns shown above? The Supervisor column will always be in the format <Last Name Characters>,<MR. or MS.><space><First Name Characters><space><Middle Intial>. The Collector will always be in the format <Last Name Characters><comma><space><First Name Characters><space><Middle Initial>

These matching expression show be in continuation to the ones inline below for the $regex variable.


$path = pushd "C:\Scripts"
$files = Dir -filter WOL.txt
$data = Get-Content -Path $files

foreach($line in $data)
{
$regex = ‘([A-Z, -]+?)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)\s+([A-Z, -]+?)\s+([A-Z, -]+?)\s+([A-Z, -]+?)\s+(WOL-DEFAULT|WRONL2-G3120A-WOL)+\s’
if ($line -match $regex)
{
$matches[1..20] -join ";"
}
}
by nohandle at 2013-03-01 13:21:29
Hi, I’d like to help you but it is kinda hard to see how exactly the result should look like. could you please send how the text look before and how after? :slight_smile:
by ellobo at 2013-03-01 13:23:55
Hi,

Here is the before:

Supervisor Collector
-------------------- --------------------
DEYOUNG,MR. RICHARD E MATIAS, SEAN J

and here would be the after:

DEYOUNG,MR. RICHARD E; MATIAS, SEAN J;
by mjolinor at 2013-03-01 13:29:49
<Last Name Characters>,<MR. or MS.><space><First Name Characters><space><Middle Intial>
[A-Z-]+,(?]+\s[A-Z]

<Last Name Characters><comma><space><First Name Characters><space><Middle Initial>
[A-Z-]+,\s[A-Z]+\s[A-Z]
by ArtB0514 at 2013-03-01 13:35:26
You could do this with Split, possibly a little easier.
$L = $line.split(','),3
$line = "$L[0],$L[1];$L[2];"