You need to match the material on both sides of 8 digits. You can do this with zero-width traversal statements, as the @S Mark example shows, or you can use an easier way to just create a backlink for 8 digits:
preg_match('/\D(\d{8})\D/', $string, $matches) $eight_digits = $matches[1];
But this will not match when numbers start or end with a line or line; for this you need to clarify it a bit:
preg_match('/(?:\D|^)(\d{8})(?:\D|$)/', $string, $matches) $eight_digits = $matches[1];
(?:...) In this case, you can specify a subset of variables using | , not counting the match as a backlink (i.e., adding it to the elements in the $matches array).
For many other details of a rich and subtle language that is the Perl-Compatible Regular Expression syntax, see http://ca3.php.net/manual/en/reference.pcre.pattern.syntax.php
source share