powershell - 正则表达式匹配一个字符串,该字符串与sql中的statment相同

时间:2016-05-11 09:13:10

标签: regex powershell

在正则表达式中,如何匹配字符串然后有这种模式?在sql中,它表示匹配字符串,如%Asia%SouthEast%

*Asia*SouthEast*

示例

Asia 2 SouthEast 9 --> false  
This is Asia 2 and SouthEast 9 --> true
Asia SouthEast --> true **There a space after SouthEast  

1 个答案:

答案 0 :(得分:1)

根据您的示例,我推断您在每个单词之前和之后都需要一个或多个字符:AsiaSouthEast

为此你可以使用这个正则表达式:

.+Asia.+SouthEast.+

示例:

> "Asia 2 SouthEast 9" -match ".+Asia.+SouthEast.+"
False
> "This is Asia 2 and SouthEast 9" -match ".+Asia.+SouthEast.+"
True

> "Asia 2 SouthEast 9" -match "[\w\s]+Asia[\w\s]+SouthEast[\w\s]+"
False
> "This is Asia 2 and SouthEast 9" -match "[\w\s]+Asia[\w\s]+SouthEast[\w\s]+"
True