Is it possible to bypass (bypass) a regular expression?

Asked

Viewed 148 times

2

I am reading a little about regex for some validations and I wanted to know if there is any way to circumvent some rule, for example:

$rule = "/[^A-Za-z0-9]/";

I found this to validate alphanumeric fields, there is some way to circumvent it and escape other characters?

  • Maybe you can help: http://stackoverflow.com/questions/30323977/how-to-bypass-reqular-expression-validation-for-specific-characters

1 answer

2


In the above example the variable $rule is getting a pattern that matches anything non-alphanumeric.

To validate alphanumerics, this pattern will probably be used to replace everything that matches it with a String of zero length ("").

If you want to know if in the cited example it is possible that some non-alphanumeric character remains in the String after the replacement the answer is NAY.

$string = 'qualquer coisa !@#$%¨&())_+';
$rule = "/[^A-Za-z0-9]/";
$resultado = preg_replace($rule, "", $string);
echo $resultado;

Upshot:

anything

Realize that not even space has passed.

It is only possible to circumvent a regular expression if there are flaws in the elaboration of it. Otherwise, as in the cited example, can’t.

  • I get it, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.