javascript – Firefox URL栏使用什么正则表达式模式?

我实际上是使用正则表达式匹配和其他东西解决问题(搜索问题).我想我会看看Google,Yahoo,Bing,Ask等的行为方式.

考虑到Firefox,Chrome,Opera和其他浏览器也有URL栏或搜索栏,我开始尝试不同的单词,然后是符号.

在Firefox中,我看到了很多不同的结果.以下是一些截图 –

^符号 – 给出一些随机结果.

《javascript – Firefox URL栏使用什么正则表达式模式?》

$符号 – 也提供随机结果.我也试过添加一个字符串,它没有给出任何结果.

《javascript – Firefox URL栏使用什么正则表达式模式?》

()括号 – 使用时给出正确的结果.它被认为是比较字符串的符号.

《javascript – Firefox URL栏使用什么正则表达式模式?》

*符号 – 这也给出了一组结果,不符合符号本身.不确定为什么那些不同的结果.

《javascript – Firefox URL栏使用什么正则表达式模式?》

〜符号 – 这也给出了一组结果,没有符号本身的匹配.不确定为什么那些不同的结果.

《javascript – Firefox URL栏使用什么正则表达式模式?》

我很想知道为什么许多符号的行为存在这种差异,而其他字符串和/或符号按预期工作.

@thanksd不是真的是duplicate.那是关于字符串匹配的工作方式.我已经知道那部分了.我清楚地问起符号.符号如何考虑匹配.

最佳答案 没有主流浏览器会将您在其位置栏中键入的内容解释为正则表达式,因为普通用户不知道正则表达式.

这就是Firefox的工作原理(基本上):

>选择要搜索的内容.通过检查browser.urlbar.default.behavior首选项以及查找special characters in the query来完成:

You can restrict what kind of results are shown in the drop down list by using customizable characters. Include the character anywhere in the address bar separated by spaces to have it restrict what results are displayed.

The characters are as follows:

  • #: Returns results that match the text in the title.
  • @: Returns results that match the text in the URL.
  • *: Returns only results that are from the bookmarks.
  • ^: Returns only results that are from the browser’s history.
  • +: Returns only results that have been tagged.
  • ~: Returns only results that have been typed.
  • %: Returns only open tabs (visible tabs, not active tab), available in Firefox 4 (SeaMonkey 2.1) and later

>在搜索内容时,每个以空格分隔的字符序列(上面的特殊字符除外)必须出现在其文本(网站标题,URL等)中,不区分大小写. (序列可能重叠.)

点赞