header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Using Regular Expression Named Captures
Last Post 26 Aug 2010 11:11 AM by glnsize. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
nyambolUser is Offline
New Member
New Member
Posts:3
Avatar

--
26 Aug 2010 10:43 AM
    Hello,

    How can I use the named captures feature for regular expressions in PS?

    It's not apparent to me how I can retrieve the capture using the name instead of locating the index.

    I'd put in an example but this message editor won't let me insert the angle brackets, even using < and > it treats them as actual HTML instead of part of the message.

    Thanks.

    mp
    "Mutable stateful objects is the new spaghetti code." - Rich Hickey
    glnsizeUser is Offline
    Basic Member
    Basic Member
    Posts:193

    --
    26 Aug 2010 11:11 AM
    [regex]::Matches("a quick brown fox jumps over the lazy dog","\S\s(?< Speed >\S+)\s(?< Color >\S+)")             
    $Matches.Speed
    $Matches.Color

    "a quick brown fox jumps over the lazy dog" |
    Where-Object {$_ -match "\S\s(?< Speed >\S+)\s(?< Color >\S+)"}|
    Select-Object @{
    name='Speed'
    Expression={$Matches.speed}
    },
    @{
    name='Color'
    Expression={$Matches.Color}
    }
    ~Glenn
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer