Re: Please tell me I dont know regex

From: Date: Sat, 16 Sep 2006 13:01:48 +0000
Subject: Re: Please tell me I dont know regex
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-241859@lists.php.net to get a copy of this message
See http://uk.php.net/manual/en/function.eregi.php#57824 Basically you don't need to escape the dash, just place it somewhere where it cannot be interpreted as indicating a range. It will then be treated literally. They do work the same using preg_match() which requires escaping. william(at)elan.net wrote:
Please try below page/program on your system entering "ab-cd" and please tell me I dont know regex - because the way I see it the results of those tests should have been the same... ----------------------------------------------------------------------- <html><body><form method=post action=<?php $PHP_SELF ?>
Please enter something with a dash here: <input type='text'
name='regex_test' /> <input type='submit' value='Submit' /> </form> <?php if (isset($_REQUEST['regex_test'])) { print "Testing ".$_REQUEST['regex_test'].' with regex /^[A-Za-z0-9\._\-]{3,63}$/ ... :'; if (ereg("^[A-Za-z0-9\._\-]{3,63}$",$_REQUEST['regex_test'])) print " Ok"; else print " Nak"; print "<br /><br />"; print "Testing ".$_REQUEST['regex_test'].' with regex /^[A-Za-z0-9\.\-_]{3,63}$/ ... :'; if (ereg("^[A-Za-z0-9\.\-_]{3,63}$",$_REQUEST['regex_test'])) print " Ok"; else print " Nak"; } print "<br /><br />Current PHP Version is: ".phpversion(); ?> </body></html>


« previous php.general (#241859) next »