Go (RE2)

Whitespace-Only Line in GO

Matches lines containing only whitespace (or empty lines).

Try it in the GO tester →

Pattern

regexGO
^\s*$   (flags: gm)

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`(?m)^\s*$`)
	input := `line one
   

line two`
	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

`^\s*$` anchors to a full line that contains zero or more whitespace characters and nothing else.

Examples

Input

line one line two

Matches

Same pattern, other engines

← Back to Whitespace-Only Line overview (all engines)