Search code examples
javascriptregexfirefoxgeckoaddress-bar

What regex pattern does Firefox URL bar use?


I am actually solving a problem(search problem) using regex patten matching and other stuffs. I thought I will have a look at how Google, Yahoo, Bing, Ask etc., behave.

Considering that Firefox, Chrome, Opera and other browsers also have a URL bar or a search bar, I started trying out different words, then symbols.

In Firefox I see a lot of different results. Here are some screenshots-

^ Symbol - Gives some random results.

^ symbol

$ Symbol - too gives random results. I also tried adding a string with this, it gave no results.

Dollar Symbol

() parentheses - when used gives proper results. Its considered as a symbol to compare like strings.

parenthesis symbols

* Symbol - This also gave a set of results with no match of the symbol itself. Not sure why those different results.

Star symbol

~ Symbol - This also gave a set of results with no match of the symbol itself. Not sure why those different results.

Tilde symbol

I am interested to know why there is such difference in behaviour for a lot of symbols, whereas, other strings and/or symbols work as expected.

-

@thanksd Not really a duplicate. That is about how string matching works. I know that part already. I am clearly asking about symbols. How are symbols considered for matching.


Solution

  • No mainstream browser interprets what you type in its location bar as a regex, bcause the average user does not know regex.

    This is how Firefox works (basically):

    1. Choose what to search in. This is done by checking the browser.urlbar.default.behavior preference as well as looking for 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
    2. When searching in something, each whitespace-separated sequence of characters (except the special characters above) must be present in its text (website title, URL, etc.), case insensitively. (Sequences may overlap.)