Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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/2/powershell/13.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
Regex 如何转义这个模糊的字符串?_Regex_Powershell - Fatal编程技术网

Regex 如何转义这个模糊的字符串?

Regex 如何转义这个模糊的字符串?,regex,powershell,Regex,Powershell,我正在使用selectstring方法和-pattern标记搜索文本文件。我想在文件中搜索以下内容的匹配:ball:[] 以下是我尝试过的: 选择字符串$textFile-pattern'ball:“`[`]” 选择字符串$textFile-模式“ball:”b单击[b单击]”(b单击=返回勾选`) 几乎所有我能想到的反勾号和引号的组合。我知道反勾号是在Powershell中转义方括号的方法,但我似乎在网上找不到包含两个空方括号、冒号和双引号的示例。转义此字符串的正确方法是什么?使用[regex

我正在使用
selectstring
方法和
-pattern
标记搜索文本文件。我想在文件中搜索以下内容的匹配:
ball:[]

以下是我尝试过的:

选择字符串$textFile-pattern'ball:“`[`]”

选择字符串$textFile-模式“ball:”b单击[b单击]”
(b单击=返回勾选`)


几乎所有我能想到的反勾号和引号的组合。我知道反勾号是在Powershell中转义方括号的方法,但我似乎在网上找不到包含两个空方括号、冒号和双引号的示例。转义此字符串的正确方法是什么?

使用
[regex]转义它::escape('text')
或使用简单的add
-SimpleMatch
来使用您的模式。如下所示:

Select-String -Path $textFile -Pattern 'ball":[]' -SimpleMatch

Select-String -Path $textFile -Pattern ([regex]::escape('ball":[]'))

使用
[regex]对其进行转义:转义('text')
或使用简单的add
-SimpleMatch
来使用未转义的模式。如下所示:

Select-String -Path $textFile -Pattern 'ball":[]' -SimpleMatch

Select-String -Path $textFile -Pattern ([regex]::escape('ball":[]'))