HTTP Status Code
Match 3-digit HTTP status codes in the 1xx–5xx range.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b[1-5]\\d{2}\\b", "g");
const input = "HTTP 200 OK";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\b[1-5]\d{2}\b")
input_text = "HTTP 200 OK"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b[1-5]\d{2}\b`)
input := `HTTP 200 OK`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\b[1-5]\d{2}\b (flags: g)Raw source: \b[1-5]\d{2}\b
How it works
Examples
Input
HTTP 200 OKMatches
200
Input
Returned 404, then 500Matches
404500
Input
no codes hereNo match
—Common use cases
- •Access log parsing
- •Error rate dashboarding
- •API test report aggregation
- •Monitoring alerts on 5xx spikes
Related patterns
Domain Name
NetworkingMatch fully-qualified domain names like example.com or api.sub.example.co.uk.
FTP URL
NetworkingMatch FTP and FTPS URLs, capturing optional credentials, host, port, and path.
Generic Connection String (URL Form)
NetworkingParse generic URL-form connection strings: `protocol://[user[:pass]@]host[:port][/database]`.
Hostname (Single Label, RFC 1123)
NetworkingValidate a single-label hostname per RFC 1123: 1–63 chars, letters/digits/hyphens, can't start or end with hyphen.
Related concepts
Alternation with the | Operator
ConceptThe pipe | matches either the expression on its left or on its right. Combine with groups to alternate over a subpattern.
How to Match Multiple Patterns (Alternation)
How-toCombine patterns with | to match either option. Wrap alternatives in a group to scope the alternation correctly.