DD
DevDash

Regex for Bot User Agent

Regex Pattern

(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\b

Detects common bot/crawler User-Agent keywords

Quick Answer

The regex pattern for bot user agent is `(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\b`. Detects common bot/crawler User-Agent keywords. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
Googlebot/2.1✓ Matches
Bingbot/2.0✓ Matches
Slurp/3.0✓ Matches
facebookexternalhit/1.1 spider✓ Matches
Mozilla/5.0 Chrome✗ No match
curl/7.68.0✗ No match
MyApp/1.0✗ No match

Code Examples

javascript

const regex = /(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\b/;
const isValid = regex.test(value);

python

import re
pattern = r'(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\b'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\b/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\b/', $value)) {
    echo "valid";
}

java

String pattern = "(?:bot|crawl|spider|slurp|fetch|archiv)(?:er)?\\b";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.