preg_match('#https?\://(?:www\.)?facebook\.com/(\d+|[A-Za-z0-9\.]+)/?#',$str,$matches);
The template is universal, so it corresponds to:
- http and https URL.
- URL with
www prefix or without it. - URL with or without trailing.
- Corresponds to Facebook's digital identifiers.
- Complies with Facebook user policies .
Usernames may contain only alphanumeric characters (AZ, 0-9) or period (".").
source share