Issue with regular expressions in C++

前端 未结 3 350
死守一世寂寞
死守一世寂寞 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:23

    This is similar sln's, but it's shorter and doesn't require a % part to match:

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

    First - everything between ^ (start of line) and $ (end of line) is optional, so an empty string is accepted.

    In an optional, non capturing group (?:...), match any number of anything but a %. Then, optionally, match a %, optionally followed by a ., and then any number of digits and finally a letter. Repeat this for any number of times.

    (I, as the others answering, and as the regex provided in the question suggests, assume that OP doesn't mean "immediately preceded by a letter", but instead followed by one, right?)

    See it here at regex101.

提交回复
热议问题