我试图从一个字符串中搜索三个数据,它们是:
first name, space ,last name (?=[A-Z][a-z]+\s[A-Z][a-z]+)
//AND
first name ,space ,last name ,and suffix (?=[A-Z][a-z]+\s[A-Z][a-z]+\s[A-Z][a-z]+)
//AND,
age (?=[0-9]{2})
从我看到的几个教程中,这三种模式似乎是:
(?=[A-Z][a-z]+\s[A-Z][a-z]+)(?=[A-Z][a-z]+\s[A-Z][a-z]+\s[A-Z][a-z]+)(?=[0-9]{2})
一起应该是我的解决方案,但它不起作用....任何建议....(它是一个 php 脚本,我使用 preg_match_all)
我的脚本:
$content = file_get_contents('http://www.somesite.com');
$pattern = '/(?=[A-Z][a-z]+\s[A-Z][a-z]+)(?=[A-Z][a-z]+\s[A-Z][a-z]+\s[A-Z][a-z]+)(?=[0-9]{2}) /';
if(preg_match_all($pattern,$content,$matches))
{
// has the pattern, do something
//$matches has all the matches from preg_match
}