Facebook正则表达式允许.和fref=ufi

Facebook regex allow . and ?fref=ufi

本文关键字:fref ufi 正则表达式 Facebook      更新时间:2023-09-26

我一直在使用以下regex来检查它是否是有效的facebook url:/^(?:(?:http|https):'/'/)?(?:www.)?facebook.com'/(?:(?:'w)*#!'/)?(?:pages'/)?(?:[?'w'-]*'/)?(?:profile.php'?id=(?='d.*))?(['w'-]*)?$/

问题是,这个正则表达式是旧的,现在一些脸书的url中有一个.?fref=ufi。例如:https://www.facebook.com/user.moreusername?fref=ufi我如何修复,使这个正则表达式接受那种url?

我一直在尝试添加'/?(?:?fref=ufi.)?'/,但没有任何运气。

只是根据您提供的内容,我发现这是可行的:

^(?:(?:http|https):'/'/)?(?:www.)?facebook.com'/(?:(?:'w)*#!'/)?(?:pages'/)?(?:[?'w'-]*'/)?(?:profile.php'?id=(?='d.*))?(['w'-'.]*)?(?:'?fref=ufi)?$

区别在于:

(['w'-'.]*)? // added the '. for matching the . literally
(?:'?fref=ufi)?$ // this was appended to the end

Regex101

这可能不适用于所有场景,因为我只有你的测试用例可以处理。