Interactive grep pattern matcher. Part of the DevTools Surf developer suite. Browse more tools in the Developer Utilities collection.
Use Cases
Search server logs for error patterns across multiple log files in one command.
Extract all import statements from a directory of source files to audit dependencies.
Filter CI output to show only failed test lines by piping to grep -i 'fail\|error'.
Practice regex syntax against real text without setting up a test harness.
Tips
Use -E flag for extended regex (ERE) to enable + and | without escaping — ERE is the default in most modern shells when using egrep.
Combine -n (line numbers) and -C 3 (context lines) to see exactly where matches occur and what surrounds them.
Use -v to invert the match and filter out lines containing a pattern — useful for removing noise from log tails.
Fun Facts
grep was written by Ken Thompson in 1973 in a single night, extracted from the ed text editor's g/re/p (global/regular-expression/print) command. The name is an acronym of that phrase.
The GNU grep implementation is significantly faster than POSIX grep on most inputs — it uses the Boyer-Moore algorithm for literal strings instead of backtracking NFA simulation.
grep -P (Perl-compatible regex) uses PCRE under the hood, which supports lookbehind and lookahead assertions. These features don't exist in POSIX basic or extended regex.
FAQ
What's the difference between grep, egrep, and fgrep?
grep uses BRE (basic regex, requires escaping +|{}). egrep (grep -E) uses ERE. fgrep (grep -F) treats the pattern as a literal string — fastest for fixed-string searches.
How do I search recursively?
Use grep -r 'pattern' ./directory. Add --include='*.ts' to restrict to file types. For large repos, ripgrep (rg) is 10-100x faster than GNU grep -r.
Does it support multi-line matching?
POSIX grep is line-by-line and cannot match patterns that span newlines. Use grep -P with (?s) modifier (Perl mode) or pcregrep for true multi-line matching.