ranger

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2017 License: MIT Imports: 4 Imported by: 0

README

ranger

Golang RegExp Ranger

ranger.go generates regexp code for numeric ranges and is inspired by dimka665/range-regex

Build Status Go Report Card codebeat badge GoDoc

what

generates a regular expression that matches any number between two given numbers.

how

first import simonwaldherr.de/go/ranger and then
call ranger.Compile(23,37) and you will get ^(2[3-9]|3[0-7])$.

why

because we can

who

me

is it any good

yes.

is it "Production Ready™"?

maybe. maybe not

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(min, max int) string

Compile generates a regular expression that matches any number between the two given numbers

Example
package main

import (
	"fmt"
	"regexp"
	"simonwaldherr.de/go/ranger"
)

func main() {
	re := ranger.Compile(23, 37)
	fmt.Println("^(" + re + ")$")

	for v := range [200]int{} {
		matched, err := regexp.MatchString("^("+re+")$", fmt.Sprint(v))
		if err != nil {
			fmt.Println(matched, err)
		}
		if matched {
			fmt.Print(v, " ")
		}
	}
}
Output:

^(2[3-9]|3[0-7])$
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL