Powershell and Regex

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
cstewart28
Posts: 12
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Mon Jan 12, 2015 1:24 pm

Powershell and Regex

Post 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

jvierra
Posts: 14437
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Powershell and Regex

Post by jvierra »

PS > 'Layout ID: LC-004' -match 'ID:\s+(.*)'
True
PS > $matches[1]
LC-004

Locked