bibi92
asked on
use variable on regex
Hello,
I try to use variable $_.fg_name on regex but the result is []
$file = "C:\test\mv_ddl.sql"
$_.fg_name = "Primary"
(Get-Content $file) | ForEach-Object {$_ -replace [regex]::Escape("ALLOW_PAG E_LOCKS = ON) ON [PRIMARY]"), "ALLOW_PAGE_LOCKS = ON) ON \[$($_.fg_name))\]" -replace [regex]::Escape(") ON [PRIMARY]"), ") ON \[$($_.fg_name))\] TEXTIMAGE_ON [LOB]"} | Set-Content $file
How can I resolve, please?
Thanks
Regards
I try to use variable $_.fg_name on regex but the result is []
$file = "C:\test\mv_ddl.sql"
$_.fg_name = "Primary"
(Get-Content $file) | ForEach-Object {$_ -replace [regex]::Escape("ALLOW_PAG
How can I resolve, please?
Thanks
Regards
You need to get that variable another way, $_ is referring to the object piped in. For example:
So you need to reference the object which contains the property you want to use. What object contains fg_name and can you post code where you are getting that object?
1,2,3 | %{ write-host $_ }
So you need to reference the object which contains the property you want to use. What object contains fg_name and can you post code where you are getting that object?
ASKER
I test Obda solution the result for the variable is \[)\].
Thanks
Thanks
ASKER
Thanks a lot
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Just use a regular variable (and please put code inside code style tags, see the buttons over the Edit field).
Open in new window