header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Regular Expression not matching
Last Post 03 Nov 2009 05:31 AM by Steven Murawski. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
PaulBUser is Offline
New Member
New Member
Posts:19
Avatar

--
02 Sep 2009 04:52 AM
    I've been learning the power of regular expressions and have grabbed a copy of Regex Buddy. But I'm having a problem with a carriage return sequence.

    My Pattern is:
    $regexec_sdcli = [regex] "Storage System:\t{1,}(\S+)\r\n\tStorage System Path:\t{1,}(/vol/(\w{5}\d{3}db)/\S+\r\n)"

    My Text is from a command output and part of it is:
    UNC Path: \\10.0.0.11\gbldn007db\gl717db1\gbldn007sg1.lun
     Storage System: gb02ldn004
     Storage System Path: /vol/gbldn007db/gl007db1/dbldn007sg1.lun
     Type: lun


    Code:
    $storage = $regexec_sdcli.matches($sdcli)
    write-host $storage.count

    Regex Buddy and my knowledge suggest the above should result in a match but it doesn't in Powershell (running 1.0). If I remove the /r/n/t between the lines and the trailing /r/n then a match occurs.

    New Pattern:
    $regexec_sdcli = [regex] "Storage System:\t{1,}(\S+)\s+Storage System Path:\t{1,}(/vol/(\w{5}\d{3}db)/\S+)"

    So what am I doing wrong?

    Paul
    Steven MurawskiUser is Offline
    Community Co-Director
    Basic Member
    Basic Member
    Posts:137

    --
    03 Nov 2009 05:31 AM
    With a bit of testing, I came up with :
    [regex] "Storage\ System:\ (\w+)\s+\n\s+Storage\ System\ Path:\ (/vol(\w{5}\d{3}db)/.*)\n"

    $sdcli = @" 
    UNC Path: \\10.0.0.11\gbldn007db\gl717db1\gbldn007sg1.lun 
        Storage System: gb02ldn004 
        Storage System Path: /vol/gbldn007db/gl007db1/dbldn007sg1.lun 
        Type: lun 
    "@ 
    $regexec_sdcli = [regex] "Storage\ System:\ (\w+)\s+\n\s+Storage\ System\ Path:\ (/vol(\w{5}\d{3}db)/.*)\n" 
    $storage = $regexec_sdcli.matches($sdcli) 
    write-host $storage.count
    
    I worked up the solution incrementally, which PowerShell is great at. I started by just matching the "Storage System" portion text like
    $regexec_sdcli = [regex] "Storage\ System:"
    
    I kept adding components and testing until I got my matching and returned the results I was looking for.
    Steven Murawski
    Blog ( blog.usepowershell.com )
    Co-Host - Mind of Root ( www.mindofroot.com )
    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