powershell Powershell -match比较器或-replace操作符或另一个操作符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Powershell -match比较器或-replace操作符或另一个操作符相关的知识,希望对你有一定的参考价值。

## 
"05752,00066,1987785578,2018/03/10T05:17:00.34,SQL_QUERY! TTransactionContext cf0e315bf1d84d59b4527546ddc0ad50: vsp_session_refresh '4D2D6A288A4A71326844C2F9', '10-Mar-2018 07:13:32'" -match "\d+,\d+,(\d+),([^,]*),.*" 

# "\d+,\d+,(\d+),([^,]*),.*" - capture Ticks then DateTime

$Matches

# Name                           Value
# ----                           -----
# 2                              2018/03/10T05:17:00.34
# 1                              1987785578
# 0                              05752,00066,1987785578,2018/03/10T05:17:00.34,SQL_QUERY! TTransactionContext cf0e315b...
## case sensitive with whole word matching
"alpha Beta gammedelta delta" -creplace "\bdelta\b","epsilon"

## using capture groups , with sample text
## $ServicePascalCase = "Patients"
## $ObjectInSentenceCase = "Patient Phone"
## $PluralCamelCase = "patientPhones"
# To capture the '$ServicePascalCase' before the =
gcb | % { $_ -replace "(\w+) = .*", "`$1" }

# This also works but shows how to escape the $ sign. 
# It is escaped differently in the regex match vs the regex replace
gcb | % { $_ -replace "(\$\w+) = .*", "`$1" } 
## trims the last entry which seems to be blank in a list of things
gcb | ? { $_ -match "(\w+)" } | % { $Matches[0] }

## 
((gcb) -split ',' | % { $_ -match "Treatment\w+" |out-null ; $Matches[0] } | % { "`\`"{treatment.$($_)}`\`"" } ) -join ',' | clip 
$beta =  ("Unknown | D:\CMS_DATA\SharedData\Img\00100\PX_032\2018-08-28\RF_00022200.cmi" -split "\|")
$beta[0]
$beta[1]

以上是关于powershell Powershell -match比较器或-replace操作符或另一个操作符的主要内容,如果未能解决你的问题,请参考以下文章

powershell PowerShell:启动PowerShell作为其他用户提升

powershell [提示输入powershell] #powershell #input #prompt

powershell 测量PowerShell命令或PowerShell脚本的速度

powershell远程下载exe并执行

powershell 使用啥端口

powershell PowerShell使用PowerShell创建本地管理员帐户