Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

What I have tried:

.
I also tried [A-Z]{3,}[a-z]* 
but this will allow:
s("AAA") and s("AAAb") but now s("AbAA")
as it will allow only if upper are consecutive.
Posted
Updated 20-Mar-17 2:39am
Comments
Patrice T 20-Mar-17 15:03pm    
Show us examples of what should match and what should not.

1 solution

You need to add the start and end of string codes.
Try this:
^[A-Z]{3,}[a-z]*$

Your Regex requires two suffixes which aren't captured, which is rather odd.

Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900