COCOS2DX c++11 Regular expressions and the use of C language regular expressions under Android--------case password check

Source: Internet
Author: User

/************************************************************************//* password Check *//* c++11 no problem, but C is a problematic *//* error case: ^[[email protected]#$% ^&* () _+ ' \\-={}\\[\\]:\; ' <>?,. \\/]{6,20}$ correct case: ^[][email protected]#$%^&* () _+ ' ={}:; ' <>?,./\ "\[-]{6,20}$ solution: The most disgusting match has three characters []--if it appears at the beginning or end of [], indicating a matching character '-', such as [^-ABC], [-ABC], [abc-]. Note that you cannot use ' \ ' to escape the first position that can appear in brackets, such as []ABC] or [^]abc][need to escape */bool Commonfunc::checkpasswordlegal (std::string strpassword, int lengthmin, int lengmax) {if (Lengmax = = 0) {#if (Cc_target_platform = = Cc_platform_win32) return Stringutil::stringveri Fication (strpassword, stringutil::format256 ("^[[email protected]#$%^&* () _+ ' \\-={}\\[\\]:\"; <>?,. \\/]+$ ")); #endif #if (Cc_target_platform = = cc_platform_android| | Cc_target_platform = = Cc_platform_ios) return stringutil::stringverification (strpassword, stringutil::format256 ("^[ ][email protected]#$%^&* () _+ ' ={}:; ' <>?,./\ "\[-]+$")); #endif}else if (Lengmax! = 0) {#if (Cc_target_platform = = Cc_platform_win32) return stringutil::stringverification ( strpassword, stringutil::format256 ("^[[email protected]#$%^&* () _+ ' \\-={}\\[\\]:\"; ' <>?,. \\/]{%d,%d}$ ", Lengthmin, Lengmax)); #endif #if (Cc_target_platform = = cc_platform_android| | Cc_target_platform = = Cc_platform_ios) return stringutil::stringverification (strpassword, stringutil::format256 ("^[ ][email protected]#$%^&* () _+ ' ={}:; ' <>?,./\ "\[-]{%d,%d}$", Lengthmin, Lengmax)); #endif}return false;} BOOL Stringutil::stringverification (std::string SRC, std::string Regular) {#if (Cc_target_platform = = Cc_platform_  WIN32) Regex pattern (regular.c_str ()); if (!regex_match (src, pattern)) {return false;} return true; #endif #if (Cc_target_platform = = cc_platform_android| |    Cc_target_platform = = Cc_platform_ios) regex_t reg; int retval = Regcomp (&reg, Regular.c_str (), reg_extended | REG_newline);    retval = Regexec (&reg, Src.c_str (), 0, NULL, 0); Cclog ("%s is%s\n", Regular.c_str (), retval = = 0?    "Legal": "illegal");    if (retval = = 0) {regfree (&reg); return true; }else{return false;} #endif}


It hurts me. For three days, regular expressions differ in different languages, especially for characters that need to be escaped.

Finally, the regular expression under the c++11 is OK, escaped normally.
The regular expression escape in C is not possible, it must be written according to the specification, "-" at the end, "]" in the first, [need to escape.

Reference Documentation:

regex--using square brackets in regular expressions POSIX regular expressions-Loverszhaokai

COCOS2DX c++11 Regular expressions and the use of C language regular expressions under Android--------case password check

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.