Boost::RegEx Syntax issue?
Hi Everyone, I have just started using BOOST in my C++ cosing projects as I am a newbie to C++ but very experienced in many other languages. I Needed to write some DLLs for Windows that would allow me to validate the complexity of porposed passwords. I have gotten a simple application togeather and it works very well at this time. The only issue I have is that it isnt validating a match correctly when I use certain RexEx expressions. For example: This expression: ^([a-zA-Z]+)(\d+)([a-zA-Z]+)$ validates strings that start with a character have a digit and then end with a character. This is great and works very well at this time. Now I go to something a bit more complex. I want to validate a new password a user sets and it has to conform to 2 of the following 4 rules: 1. Have uppercase letter 2. Have lower case letter 3. Have 0-9 4. Have a special character !@#$%^&* This RegExs Expression works very well in my other applications written in C# (DOTNET REGex) and also works very well in PERL applications too: (?=\w*[a-z])(?=\w*[A-Z])|(?=\w*\d)(?=\w*[a-z])|(?=\w*[a-z])(?=\w*\d)|(?=\w*[a-z])(?=.*[@#$%^&])|(?=\w*\d)(?=\w*[A-Z])|(?=\w*[A-Z])(?=.*[@#$%^&])|(?=\w*\d)(?=.*[@#$%^&]) Ok I know its a doosy, but I works great everywhere except the application I am running BOOST with. I keep the expression in a registry key so I can edit easily instead of recompiling the DLL if I want to change the RegEx. Here is the code I am using in my C++ project and its failing to validate passwords that match the policies: // Validate password against regular expression wregex wrePassword(DEFAULT_REGEX); WriteToLog("Going to retrieve RegEx from Registry"); GetPasswordRegExFromRegistry(wrePassword); WriteToLog("Going to run match"); // Prepare iterators wstring::const_iterator start = wstrPassword.begin(); wstring::const_iterator end = wstrPassword.end(); match_resultswstring::const_iterator what; unsigned int flags = match_default; bMatch = regex_match(start, end, what, wrePassword); If all is working corectly the following passwords should pass the RegEx expression I have posted above (it works fiune in PERL or C#/VB.NET): Password Password1 password1 p@ssword Any of those should work just fine and they dont. Anyone able to hep me with this one? Your help is greatly appreciated. I just cant figgure out why a syntax I use in PERL or C#/VB.NET works great but wont work in BOOST. -Timothy
bMatch = regex_match(start, end, what, wrePassword);
If all is working corectly the following passwords should pass the RegEx expression I have posted above (it works fiune in PERL or C#/VB.NET):
Password Password1 password1 p@ssword
Any of those should work just fine and they dont. Anyone able to hep me with this one? Your help is greatly appreciated. I just cant figgure out
why a syntax I use in PERL or C#/VB.NET works great but wont work in BOOST.
I believe that you are trying to match the expression against not the whole
of the password (which is what regex_match tries to do), but only match a
prefix of the password string? If that is the case, then you need to use
regex_search, with the match_continuous flag set. Here is my test code:
#include <iostream>
#include <string>
#include
participants (2)
-
John Maddock
-
Timothy H. Schilbach