开发者

Regular expression like string == string

开发者 https://www.devze.com 2023-02-06 13:08 出处:网络
What would开发者_如何学Python be regular expression for for example \'aa\' to match only \'aa\'Try this:

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

精彩评论

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