本文介绍了regex:如何匹配以括号“)"结尾的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配以')'结尾的字符串.我使用模式:

I want to match string ending with ')' .I use pattern :

 "[)]\b" or ".*[)]\b"

它应该与字符串匹配:

x=main2.addMenu('Edit')

但是它不起作用.怎么了?

But it doesn't work. What is wrong ?

推荐答案

\ b仅与单词边界处的位置匹配.将其视为(^\w|\w$|\W\w|\w\W),其中\ w是任何字母数字字符,\ W是任何非字母数字字符.括号是非字母数字,因此\ b不会与之匹配.

The \b only matches a position at a word boundary. Think of it as a (^\w|\w$|\W\w|\w\W) where \w is any alphanumeric character and \W is any non-alphanumeric character. The parenthesis is non-alphanumeric so won't be matched by \b.

只需匹配一个假体,然后使用\)$

Just match a parethesis, followed by the end of the string by using \)$

这篇关于regex:如何匹配以括号“)"结尾的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 22:41