Page 1 of 1

Powershell and Regex

Posted: Thu Sep 01, 2016 8:41 am
by cstewart28
I have a document that has a structured layout, such as:

Layout ID: LC-004
Name: Items 1
Description: Description of stuff
Type: Server
Equipment ID: 3sdrsqq
PPEquipment ID: PP-003
IP Address: 10.0.0.1

This is on a couple pages, I need to put all the values into an array

Here is here I'm starting from:

$file = get-content "C:\tools\Configuration.htm"

$regex = "^Layout ID:\s*(.+)"

$ID = ([regex]::Matches($file,$regex) | %{$_.value})

The result I get for $ID is Layout ID: LC-004 when all I want is LC-004

Thanks

Re: Powershell and Regex

Posted: Thu Sep 01, 2016 10:06 am
by jvierra
PS > 'Layout ID: LC-004' -match 'ID:\s+(.*)'
True
PS > $matches[1]
LC-004