Answer the question
In order to leave comments, you need to log in
regexp in php. Checking a string for the presence of the desired sequences?
There is a string consisting of sequences matching this regular expression: %u00[0-9][0-9a-zA-Z]
For example:
%u003c%u0073%u0063%u0072%u0069%u0070%u0074%u003e
%u003c%u0073%u0063%u0072%u0069%u0070%u0074%u003e
%u003c
%u0046%u005s
asd
%a003da
%k41ad
blah blah blah
%u003c%u0073%u0063%
%u003c%u0073ASFQ%u0063
Answer the question
In order to leave comments, you need to log in
If we take it for granted that we are talking about escaped unicode, where %u starts the character code, followed by a hexadecimal representation, then the following regular expression will do:/^(?:%u[\dabcdef]{4})+$/i
In your third positive test, c is Russian, but I think why the test is failing =)
function checkStr( $sInput ) {
$sRegexp = '~^(:?%u00[0-9][0-9a-zA-Z])++$~';
return preg_match($sRegexp, $sInput);
}
assert('checkStr("%u003c%u0073%u0063%u0072%u0069%u0070%u0074%u003e")');
assert('checkStr("%u003c")');
assert('checkStr("%u0046%u005c")');
assert('checkStr("asd")==false');
assert('checkStr("%a003da")==false');
assert('checkStr("%k41ad")==false');
assert('checkStr("Бла бла бла")==false');
assert('checkStr("%u003c%u0073%u0063%")==false');
assert('checkStr("%u003c%u0073ASFQ%u0063")==false');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question