Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Regex


ghost's Avatar
0 0

Does anyone know any good Regex generator scripts which would work for large strings. IE a regex which could test a whole script for a series of commands ie a script which would return

<?php echo "lol"; ?> <?PHP echo "LOL"; ?> <?php print "lol"; ?> <?php echo "lol"; echo "meh"; ?> . . .

as true but would return things like

<?php echo "loll"; ?> as false


ghost's Avatar
0 0

There is not really any good programs…Regex are always better when they are "Home made"…

But to test these regelura expresion, use the function preg_match


ghost's Avatar
0 0

I usually do do them "home-made" but try making a home made regex for 30-40 lines of code involving OR functions


ghost's Avatar
0 0

Actually, it shouldn't be too difficult… Just put the code in some variable…

If it contains a lot of single and double quotes, construct it like:

$code = &lt;&lt;&lt;END

&lt;?php

    // My Code here

?&gt;

END;

 $regex = str_replace(&#39;/&#39;, &#39;&#92;/&#39;, preg_quote($code));

 echo preg_match(&quot;/^$regex$/&quot;, $code) ? &#39;Good&#39; : &#39;Bad&#39;;

$regex = str_replace('/', '\/', preg_quote($code));

Should form the REGEX for you :)


ghost's Avatar
0 0

'/(<\?){1}(php|PHP){1}(.)([$][a-z])/' '/(<\?){1}(php|PHP){1}(.)([$])[a-z]/' '/(<\?){1}(php|PHP){1}(.)([$])([a-z])/'

None of theses preg_match <?php $a

But '/(<\?){1}(php|PHP){1}(.)([$])/'

matches

<?php $

Help!!!


ghost's Avatar
0 0

'/^\<\? php \$[a-Z]/i'

Try that…