Search code examples
javascriptuser-agentnavigator

What is /i in navigator.userAgent.match


I'm curious what /i is in:

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }};
}

Source: https://www.sitepoint.com/navigator-useragent-mobiles-including-ipad/

Could anyone tell me what /i is exactly? I've searched a lot of websites for things about the navigator.userAgent.Match but none explain what /i is, sometimes it also is /g


Solution

  • /heregoesregex/flags is literal for Regular Expression in many languages (including javascript). After the last slash you can specify flags for regular expression. List of available flags for javascript includes:

    • g Global search.
    • i Case-insensitive search.
    • m Multi-line search.
    • y "sticky" search that matches starting at the current position in the target string