string search in select statement

I am trying to search a string from a text file with a regex and include it with a select statement:
Here is the string:

C:\SQLIO>echo Thu 8/12/2016  0:15:15.25 

This is the select statement I am trying to include it to:

 @{Name="MinLat_ms"; Expression={[int]([regex]::Match($_,"Min.{0,}?\:\s(\d+)?").Groups[1].Value)}},`
			   @{Name="date1"; Expression={[string]([regex]::Match($_,"echo\W+").Groups[1].Value)}},` 

date1 is the value that is not working for me, can someone please help me. thank you :slight_smile:

I believe you’ve forgot simple brackets around \W+ in your pattern to create a capturing group for it.

thanks for your input, I just tried that, still the value doesnt get captured to date1. Is there anything else that I am missing?

The non-word character class \W doesn’t contain all the characters necessary to successfully capture what you’re looking for. You could change \W+ to . and it should capture everything after echo.

[string]([regex]::Match($_, 'echo(.+)$').Groups[1].Value).Trim()

It’s not clear what you are expecting from the output, but…

[regex]::Match("C:\SQLIO>echo Thu 8/12/2016  0:15:15.25 ","(echo\W+)").groups[1].value
echo

I tried what you suggested, not sure if I am doing something really stupid, date1 still turns up empty, but other regex’s work in the same statement. I have included one that works below as well:

@{Name="MinLat_ms"; Expression={[int]([regex]::Match($_,"Min.{0,}?\:\s(\d+)?").Groups[1].Value)}},`
			   @{Name="date1"; Expression={[string]([regex]::Match($_,"echo(.+)$").Groups[1].Value).Trim()}},`

I am trying to read a text file, and get the date part which is part of a string containing “echo”. This is then going to be assigned to date1 as part of a select statement along with other values read from the text file. part of the code below. It is to date1 that I am trying to read this string into:

@{Name="MinLat_ms"; Expression={[int]([regex]::Match($_,"Min.{0,}?\:\s(\d+)?").Groups[1].Value)}},`
			   @{Name="date1"; Expression={[string]([regex]::Match($_,"echo(.+)$").Groups[1].Value).Trim()}},`

hmmm … like this?

‘echo Thu 8/12/2016  0:15:15.25’ -match ‘echo\s+(\w{3}\s+\d{1,2}/\d{1,2}/\d{4}\s+\d{1,2}:\d{1,2}:\d{1,2}.\d{1,2})’ | Out-Null
Get-Date $Matches[1]

One expression for your select statement:

[DateTime]([regex]::Match("C:\SQLIO>echo Thu 8/12/2016  0:15:15.25 ","echo\s+\w{3}\s+(\d{1,2}/\d{1,2}/\d{4}\s+\d{1,2}:\d{1,2}:\d{1,2}\.\d{1,2})").groups[1].value)