I need a way for matching a "format" string. It should have either one or two %d
tokens, any only one %s
token. Also preferably it wouldn't allow any other formatting tokens such as %f
etc. I've come up with a few halfway-solutions of my own that do not manage to get the full job done:
.*?(\%d).*(\%(?=d|s)).* //Doesn't fit requirements
.*?(\%d).*(\%d).*(\%s).* //Doesn't allow for any ordering of the tokens
My thought is perhaps searching for the sole %s
token and doing lookarounds, but I'm not entirely certain how to go about doing that (regex is not my strongest suit). This is intented for use an a Java library, and I'm open to non-regex solutions, however regex solutions need to match the entire string (and I'd prefer not doing two/three different regex searches on a format string).
It should match %d:%d:%s
as well as %d:%s
for example, but not %d:%d:%d:%s
or %f:%d:%s
. Essentially this would be the requirements of the string:
- One or two
%d
tokens - One
%s
token