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
| Input | Result |
|---|---|
| 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
Subdomain Extraction
Extracts the subdomain from a URL or domain name
Protocol Detection
Detects and captures the protocol from a URL
Port Number
Extracts port number from a URL or host string
Query Parameter
Extracts key-value pairs from URL query strings
HTTP vs HTTPS URL
Matches HTTP or HTTPS URLs and captures the protocol
Data URL
Matches data: URL scheme with optional MIME type and base64 encoding