Thursday, 15 September 2011

Regex - If contains '%', can only contain '%20' -


I want to create a regular expression for the following scenario:

If a string is a percentage character ( % ) then it can only be the following: % 20 , and can not be preceded by any other '% '.

So if for example, then % 25 will be rejected. For example, the following string would be valid:

http://www.test.com/?&Name=My%20Name%20Is%20Vader

< P> but it will fail:

http://www.test.com/?&Name=My%20Name%20Is%20VadersAccountant%25

%% 25

Any help would be greatly appreciated,

Kyle


Edit:

In short, the scenario is that a link is written in an encoded state and then launched by Javascript. No decoding works, I tried Net decoding and JS decoding, each had the same result - the results remain encoded upon execution.

% is not required:

  / ^ [^% ] * (% 20 [^%] *) * $ /  

No comments:

Post a Comment