DD
DevDash

Regex for Browser User Agent

Regex Pattern

Mozilla\/5\.0\s+\([^)]+\)

Detects browser-style User-Agent strings starting with Mozilla/5.0

Quick Answer

The regex pattern for browser user agent is `Mozilla\/5\.0\s+\([^)]+\)`. Detects browser-style User-Agent strings starting with Mozilla/5.0. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
Mozilla/5.0 (Windows NT 10.0; Win64; x64)✓ Matches
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15)✓ Matches
Googlebot/2.1✗ No match
curl/7.68.0✗ No match
Python-urllib/3.8✗ No match

Code Examples

javascript

const regex = /Mozilla\\/5\.0\s+\([^)]+\)/;
const isValid = regex.test(value);

python

import re
pattern = r'Mozilla\/5\.0\s+\([^)]+\)'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /Mozilla\/5\.0\s+\([^)]+\)/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/Mozilla\\/5\.0\s+\([^)]+\)/', $value)) {
    echo "valid";
}

java

String pattern = "Mozilla\\/5\\.0\\s+\\([^)]+\\)";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.