Issue with regular expressions in C++

前端 未结 3 379
死守一世寂寞
死守一世寂寞 2021-01-27 13:03

I tried to use the following regular expression, which already works in C#, in C++ as well but it\'s not working in C++.

         


        
3条回答
  •  渐次进展
    2021-01-27 13:36

    Here you go, all % in string must be compliant.
    If so, match the entire string, if not, don't match
    the string.

    I suggest you do this with i.e. if ( regex_search( sTarget, sRx, sMatch, flags ) )
    but regex_match() would do the same thing.

    ^(?:[^%]*%(?:\.[0-9]*)?[a-z])+[^%]*$

    Expanded

     ^                             # BOS
     (?:                           # Cluster begin
          [^%]*                         # Not % characters
          %                             # % found
          (?: \. [0-9]* )?              # optional .###
          [a-z]                         # single a-z required
     )+                            # Cluster end, 1 to many times
     [^%]*                         # Not % characters
     $                             # EOS
    

提交回复
热议问题