在正则表达式中,如何匹配字符串然后有这种模式?在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
答案 0 :(得分:1)
根据您的示例,我推断您在每个单词之前和之后都需要一个或多个字符:Asia
和SouthEast
。
为此你可以使用这个正则表达式:
.+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