开发者

Regular expression like string == string

What would开发者_如何学Python be regular expression for for example 'aa' to match only 'aa'


Try this:

^aa$

The ^ and $ are anchors for the start and end of the line. If you have a multiline string you might also want to try:

\Aaa\Z

Which you need depends on what regular expression engine you are using and on whether or not there can be newlines in your string.


If you want to match any doubled character:

/(.)\1/

If you want to match any repeated character:

/(.)\1+/

If you want to match only repeated letters:

/(\w)\1/

...etc...

If you explain your problem better, we can better help...


Why would you use a regex for this?

string s = "aa";

bool match = (s == "aa");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜