Go (RE2)

HTTP Status Code in GO

Match 3-digit HTTP status codes in the 1xx–5xx range.

Try it in the GO tester →

Pattern

regexGO
\b[1-5]\d{2}\b   (flags: g)

Go (RE2) code

goGo
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.

How the pattern works

Leading digit 1–5 covers all standard class codes (informational, success, redirect, client error, server error), followed by any two digits. Word boundaries prevent partial matches.

Examples

Input

HTTP 200 OK

Matches

  • 200

Input

Returned 404, then 500

Matches

  • 404
  • 500

Input

no codes here

No match

Same pattern, other engines

← Back to HTTP Status Code overview (all engines)