In a given program, a string should start and finish with a percentage sign and can contain any number of characters in-between. Therefore, the following strings should be valid:
"%%"
"% %"
"%a%"
"%1%"
"% a1a %"
"%%%"
The following strings (for example) would therefore be invalid:
" %%"
"%% "
" % "
" a%%b "
I am trying to validate these using regular expressions but cannot figure the correct expression. In C# I currently have:
Regex.IsMatch(stringToValidate, "%.*%")
All strings provided above currently match. But I do not want it to match the set of invalid strings.