You do not seem to be getting the point: you do not need to perform a check. If there are no characters to change, the replace operation will leave everything as is. The check is pointless and useless.
Scriptlets and the JSTL/EL are not meant to work together -- they are purposefully designed as such to discourage the use of scriptlets. What are you trying to accomplish via the scriptlet variable that can be accomplished by better means?