I tried to use the following regular expression, which already works in C#
, in C++
as well but it\'s not working in C++
.
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.