Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果不为Null,则替换为regex;如果为Null,则不执行任何操作_Regex_String_Powershell_Replace_Null - Fatal编程技术网

如果不为Null,则替换为regex;如果为Null,则不执行任何操作

如果不为Null,则替换为regex;如果为Null,则不执行任何操作,regex,string,powershell,replace,null,Regex,String,Powershell,Replace,Null,我只希望在$\ux.Skuname不为Null且不为空时应用正则表达式,这样它就不会将Null转换为字符串。这可能吗?如果可能,如何实现 (Get-SQLInstance -Computername $Computer | foreach { $_.Skuname }) -replace '(\w+) .+', '$1' 只需在foreach中包含if/then语句,如下所示: (获取SQLInstance-Computername$Computer | foreach{if($\.Skuna

我只希望在$\ux.Skuname不为Null且不为空时应用正则表达式,这样它就不会将Null转换为字符串。这可能吗?如果可能,如何实现

(Get-SQLInstance -Computername $Computer | foreach { $_.Skuname }) -replace '(\w+) .+', '$1'

只需在foreach中包含if/then语句,如下所示:

(获取SQLInstance-Computername$Computer | foreach{if($\.Skuname){$\.Skuname-replace'(\w+).+','$1'}}


希望这有帮助!

这是我的荣幸!