PowerShell转义通配符

栏目: 编程工具 · 发布时间: 6年前

内容简介:PowerShell转义通配符

当你使用 –like操纵符,它支持3个通配符,” * “代表任意个数的字符,” ? “代表一个字符,“[a-z]”代表一个字符列表。然而PowerShell中转义字符“ ` ”(反引号)很少有人知道,它可以转义通配符。

所以,当你想验证“*”是否在某个字符串中,你可能会写成这样,实际上这样恰恰错了。

'*abc' -like '*abc'

之所以错,是因为下面的字符串也会被匹配返回true:

'xyzabc' -like '*abc'

因此如果要验证 “*”,一定得保证它不是通配符,此时就需要转义字符:

PS> '*abc' -like '`*abc'
True

PS> 'xyzabc' -like '`*abc'
False

当你想匹配反引号时,同样也需要转义字符

# 错误:
PS> "xyzabc" -like "`*abc"
True

# 正确:
PS> "xyzabc" -like "``*abc"
False

PS> "*abc" -like "``*abc"
True

原文链接: Escape Wildcards


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to the Design and Analysis of Algorithms

Introduction to the Design and Analysis of Algorithms

Anany Levitin / Addison Wesley / 2006-2-24 / USD 122.00

Based on a Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, "Introduction to the Design and Analysis of Algorithms" presents the subject in a c......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具