我有这个字符串
public fileChangeEvent(fileInput: any){
if (fileInput.target.files && fileInput.target.files[0]) {
var reader = new FileReader();
reader.onload = function (e : any) {
$('#preview').attr('src', e.target.result);
}
reader.readAsDataURL(fileInput.target.files[0]);
}
}
我希望从字符串中获取$string="@smn and @someone are web developers"
和@smn
。我该怎么做?
答案 0 :(得分:0)
将preg_match_all
与正则表达式/(?<!\w)@\w+/
$string="@smn and @someone are web developers";
preg_match_all('/(?<!\w)@\w+/',$string,$matches);
print_r($matches[0]);
<强> DEMO 强>