Verbal expressions instead of regular ones invariably simplify coding in PHP and Javascript
to make regular expressions simpler you can use an interesting class
http://thechangelog.com/stop-writing-regular-expressions-express-them-with-verbal-expressions/
and write them like this
$regex = new VerbalExpressions;
var tester = VerEx()
.startOfLine()
.then( "http" )
.maybe( "s" )
.then( "://" )
.maybe( "www." )
.anythingBut( " " )
.endOfLine();
if($regex->test("http://my-city.com.ua"))
echo "this is a url";
else
echo "invalid url";
if (preg_match($regex, 'http://github.com')) {
echo 'this is a url';
} else {
echo 'invalid url';
}
https://github.com/VerbalExpressions/PHPVerbalExpressions
for javascript
Comments