-1
<?php
$teststring = <<<STR
aqbrakadabra
doom
<style>
<script>
sdgdfsf
<?php
<?
dfsaasdf
<? phpinfo(); ?>
STR;

 print preg_replace("/\<\?(php){0,1}|(sys)[a-zA-Z0-9\s]+|(\?\>)|(.+)[;]|([\<][a-zA-Z0-9\/]+[\>])/iug","$$",$teststring); 
//this expression returns no results even though $teststring has matching expressions

?>

At first I thought the problem was my regular expression or the specifics of preg_replace or preg_match - but as it turned out, the problem was much less complicated.

1 Answers1

-1

As it turned out, the problem was the switches in the regular expression:

<?php
$teststring = <<<STR
aqbrakadabra
doom
<style>
<script>
sdgdfsf
<?php
<?
dfsaasdf
<? phpinfo(); ?>
STR;

 print preg_replace("/\<\?(php){0,1}|(sys)[a-zA-Z0-9\s]+|(\?\>)|(.+)[;]|([\<][a-zA-Z0-9\/]+[\>])/iug","$$",$teststring); 
//this expression returns no results even though $teststring has matching expressions

?>

and this, working good:

<?php
$teststring = <<<STR
aqbrakadabra
doom
<style>
<script>
sdgdfsf
<?php
<?
dfsaasdf
<? phpinfo(); ?>
STR;

 print preg_replace("/\<\?(php){0,1}|(sys)[a-zA-Z0-9\s]+|(\?\>)|(.+)[;]|([\<][a-zA-Z0-9\/]+[\>])/i","$$",$teststring); 
//this expression returns no results even though $teststring has matching expressions

?>

It was enough to replace "/[regexp]/iug" with "/[regexp]/i"