Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 11, 2020 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/ae1b9cf3073b54aeddd2234f5e5ad7ac to your computer and use it in GitHub Desktop.
Save lbvf50mobile/ae1b9cf3073b54aeddd2234f5e5ad7ac to your computer and use it in GitHub Desktop.
Just PHP FUN 100.
<?php
# https://www.codewars.com/kata/5269452810342858ec000951 Coordinates Validator.
function isValidCoordinates($coordinates) {
$c = $coordinates;
echo "Input: $c\n;";
$ans = preg_match('/^-?(\d|([0-8]\d)|(90))(\.\d{1,8})?, -?(\d|(\d\d)|(0\d\d)|(1[0-7]\d)|(180))(\.\d{1,8})?$/',$c);
return (bool) $ans;
}
@lbvf50mobile
Copy link
Author

lbvf50mobile commented Sep 11, 2020

About rubs33 and chrisom solutions.

From this example I got some information about PHP Backreference to the named subpatterns in Regex, Perl Compatible Regular Expression if more precisely.

Back references to the named subpatterns can be achieved by (?P=name) or, 
since PHP 5.2.2, also by \k<name> or \k'name'. 
Additionally PHP 5.2.4 added support for \k{name} and \g{name}, and PHP 5.2.7 for \g<name> and \g'name'.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment