header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
using -replace or [regex]::replace to replace substring but using other data to match first
Last Post 17 Sep 2010 05:39 AM by George Howarth. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jonnygUser is Offline
New Member
New Member
Posts:16
Avatar

--
16 Sep 2010 05:49 AM
    Hi All,

    I'm trying to find a way to replace all the dots with commas in this string that are not part of the date or time at the beginning

    01/29/2010 9:32:22.196 168 99.99999234234 99.34234324234234 95.23123324234324 47.321999230984

    what I want is a line that looks like this

    01/29/2010 9:32:22.196 168 99,99999234234 99,34234324234234 95,23123324234324 47,321999230984

    something like this \s\d+(\.)\d+ will match the number but if I then need to just do the replace on the group in the () and i cannot figure out how todo this.

    Hope that makes sense

    JonG
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    17 Sep 2010 05:39 AM

    Try this:

    $before = "01/29/2010 9:32:22.196 168 99.99999234234 99.34234324234234 95.23123324234324 47.321999230984"

    $regex = '(?< date >\d{1,2}/\d{1,2}/\d{1,4})\s(?< time >

    if ($before -match $regex)
    {
        $after = $Matches["date"] + ' ' + $Matches["time"] + ' ' + ($Matches["someData"] -replace '\.', ',')
    }

    $after

    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