Is it possible to bypass a regular expression?

2

I'm reading a bit about regex for some validations and 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, is there any way to circumvent this and escape other characters?

    
asked by anonymous 25.08.2016 / 04:21

1 answer

2

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

To validate alphanumeric, this pattern will probably be used to replace everything that matches it with a zero-length string ("").

If you want to know if it is possible for a non-alphanumeric character to remain in the String after the substitution, the answer is NOT .

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

Result:

  

any thing

Notice that space has not even passed.

It is only possible to circumvent a regular expression if there are any errors in its elaboration. Otherwise, as in the example quoted, does not give .

    
25.08.2016 / 04:37