std::string s("AAA");
std::smatch m;
std::regex e("(?=.{3,}[A-Z])(?=.{0,}[a-z]).*");
output = std::regex_search(s, m, e);
Here it should have 3 or more uppercase letters and zero or more lowercase letter.
However the output is zero meaning it fails. When I try replace zero with 1 and
s("AAA4") it works fine.
So now I want it to allow zero or more but it seems like it is not accepting zero
I even tried quantifier (*) which is equivalent to {0,} still not working.
Thanks for replying.
This regex works fine when lowercase/uppercase are consecutive, however in my case I want to find lowercase/uppercase regardless their position.
OP: with apologies, after reading and re-reading your posts I'm still finding it difficult to understand what it is that you're really trying to do. Could you please spell it out in a few simple sentences, possibly with an example? thanks
Here is an example:
string1 "AAA"
string2 "AAAb"
string3 "AbAA"
The following regex works with string1 and string2 as the uppercase are consecutive:
[A-Z]{3,}[a-z]*
The following regex works with string2 and string3 but it will not work when there are no lowercase even though I specified 0.
(?=.{3,}[A-Z])(?=.{0,}[a-z]).*
What I am looking for is a regex to work with all of them with following cases:
- Allow 0 or more occurrence of lowercase
- Validate 3 uppercase in string but they dont have to be consecutive like string 3