flux

package module
v0.0.0-...-80737e7 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2015 License: MIT Imports: 3 Imported by: 0

README

Coverage Status Build Status API Documentation

Description

Fluent Regular Expressions in golang is a port of https://github.com/selvinortiz/flux by Selvin Ortiz

Requirements

  • golang
    • Created and Tested with Version 1.4.2

Install

Flux is available via go get github.com/alexanderbartels/flux

Example

This simple example illustrates the way you would use flux and it's fluent interface to build complex patterns.

package main

import (
   "flux"
)

func main() {
   // create the regex 
   regex := flux.NewFlux().StartOfLine().Find("http").Maybe("s").Then("://").Maybe("www.").AnythingBut(".").Either(".co", ".com", ".de").IgnoreCase().EndOfLine()
   
   // print the created regex
   fmt.Println("Regex: ", regex.String())
   // or
   fmt.Println("Regex: ", regex)
   
   // The subject string (URL)
   subject := 'http://www.selvinortiz.com';
   
   // Match 
   match, _ := regex.Match("http://selvinortiz.com")
   if match {
      fmt.Println("Matched")
   }
   
   // Replace
   repl := regex.Replace("http://selvinortiz.com", "$5$6")
   if repl == "selvinortiz.com" {
      fmt.Println("Replacement ok")
   }
}

For other examples, please see the flux_test.go file.

License

Flux is released under the MIT license

TODO

  • Add CI Builds
  • API Documentation
  • SourceCode Documentation
  • Branching, Changelog, Versioning / using semver

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flux

type Flux struct {
	// contains filtered or unexported fields
}

func NewFlux

func NewFlux() *Flux

creates a new Flux instance

func (*Flux) Any

func (f *Flux) Any(value string) *Flux

Creates a [%s] search param

func (*Flux) Anything

func (f *Flux) Anything() *Flux

Adds a wildcard parameter

func (*Flux) AnythingBut

func (f *Flux) AnythingBut(value string) *Flux

Matches anything but the given arguments

func (*Flux) Clear

func (f *Flux) Clear() *Flux

Clears all pattern components to create a fresh expression

func (*Flux) Compile

func (f *Flux) Compile() (*regexp.Regexp, error)

regexp.Compile

func (*Flux) Digits

func (f *Flux) Digits() *Flux

func (*Flux) Either

func (f *Flux) Either(values ...string) *Flux

Takes multiple arguments are creates an OR list. Output would be one|two|three etc

func (*Flux) EndOfLine

func (f *Flux) EndOfLine() *Flux

Helper for the $ suffix

func (*Flux) Find

func (f *Flux) Find(value string) *Flux

-------------------------------------------------------------------------------- @=LANGUAGE -------------------------------------------------------------------------------- Alias to Flux#then

func (*Flux) IgnoreCase

func (f *Flux) IgnoreCase() *Flux

Adds a modifier to ignore cases

func (*Flux) Length

func (f *Flux) Length(min, max int) *Flux

func (*Flux) Letters

func (f *Flux) Letters() *Flux

func (*Flux) LineBreak

func (f *Flux) LineBreak() *Flux

func (*Flux) Match

func (f *Flux) Match(value string) (bool, error)

func (*Flux) MatchNewLine

func (f *Flux) MatchNewLine() *Flux

func (*Flux) Maybe

func (f *Flux) Maybe(value string) *Flux

Optional search parameter

func (*Flux) Min

func (f *Flux) Min(min int) *Flux

func (*Flux) Multiline

func (f *Flux) Multiline() *Flux

Adds the 'm' modifier

func (*Flux) MustCompile

func (f *Flux) MustCompile() *regexp.Regexp

To reuse the compiled regexp regexp.MustCompile

func (*Flux) NamedGroup

func (f *Flux) NamedGroup(name, value string) *Flux

very experimental

func (*Flux) NamedMatches

func (f *Flux) NamedMatches(s string) (map[string]string, error)

returns a map with all named matches experimental.... (Currently Only for groups added with #NamedGroup(name, rawGroup))

func (*Flux) Once

func (f *Flux) Once() *Flux

alias for Min(1)

func (*Flux) OneLine

func (f *Flux) OneLine() *Flux

Removes the 'm' modifier if it exists

func (*Flux) OrTry

func (f *Flux) OrTry() *Flux

experimental... This is bound to change

func (*Flux) Range

func (f *Flux) Range(values ...string) *Flux

Creates a range character class You can create a-z0-9 by calling Flux.range("a", "z", "0", "9")

func (*Flux) RawGroup

func (f *Flux) RawGroup(value string) *Flux

func (*Flux) Replace

func (f *Flux) Replace(src, repl string) string

func (*Flux) StartOfLine

func (f *Flux) StartOfLine() *Flux

-------------------------------------------------------------------------------- MODIFIERS -------------------------------------------------------------------------------- Helper for the ^ prefix

func (*Flux) String

func (f *Flux) String() string

concatenate prefixes/pattern/suffixes/modifiers into a regular expression prints the current String representation from the regex

func (*Flux) Tab

func (f *Flux) Tab() *Flux

func (*Flux) Then

func (f *Flux) Then(value string) *Flux

Adds a search parameter

func (*Flux) Word

func (f *Flux) Word() *Flux

Jump to

Keyboard shortcuts

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