Documentation
¶
Index ¶
Examples ¶
- BReplacement.ReplaceFunc
- BReplacement.ReplaceLiteral
- BReplacement.ReplaceTemplate
- Bytes.Contains
- Bytes.Find
- Bytes.Replace
- RReplacement.ReplaceFunc
- RReplacement.ReplaceLiteral
- RReplacement.ReplaceTemplate
- Runes.Contains
- Runes.Find
- Runes.Replace
- SReplacement.ReplaceLiteral
- SReplacement.ReplaceTemplate
- String.Contains
- String.Find
- String.Replace
- Subs.At
- Subs.Iter
- Subs.Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BReplacement ¶
func (BReplacement) ReplaceFunc ¶
func (r BReplacement) ReplaceFunc(f func([]byte) []byte)
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[a-z]+`)
input := []byte("number 42 is the answer")
var result []byte
matches := rex.Bytes(input).Replace(&result)
for match := range matches {
match.ReplaceFunc(func(b []byte) []byte {
return append(bytes.ToUpper(b[:1]), b[1:]...)
})
}
fmt.Println(string(result))
}
Output: Number 42 Is The Answer
func (BReplacement) ReplaceLiteral ¶
func (r BReplacement) ReplaceLiteral(val []byte)
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := []byte("number 42 is the answer")
var result []byte
matches := rex.Bytes(input).Replace(&result)
for match := range matches {
newVal := bytes.ToUpper(match.Content)
match.ReplaceLiteral(newVal)
}
fmt.Println(string(result))
}
Output: number 42 IS THE answer
func (BReplacement) ReplaceTemplate ¶
func (r BReplacement) ReplaceTemplate(val []byte)
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := []byte("number 42 is the answer")
var result []byte
matches := rex.Bytes(input).Replace(&result)
for match := range matches {
template := []byte(`[$1]`)
match.ReplaceTemplate(template)
}
fmt.Println(string(result))
}
Output: number 42 [is] [the] answer
type Bytes ¶
type Bytes struct {
// contains filtered or unexported fields
}
func (Bytes) Contains ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[0-9]+`)
input := []byte("number 42 is the answer")
contains := rex.Bytes(input).Contains()
if contains {
fmt.Println("the byte slice contains a regexp match")
}
}
Output: the byte slice contains a regexp match
func (Bytes) Find ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[a-z]+`)
input := []byte("never gonna give you up")
matches := rex.Bytes(input).Find()
for match := range matches {
fmt.Println(match.Span.Start, string(match.Content))
}
}
Output: 0 never 6 gonna 12 give 17 you 21 up
func (Bytes) Replace ¶
func (b Bytes) Replace(res *[]byte) iter.Seq[BReplacement]
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := []byte("number 42 is the answer")
var result []byte
matches := rex.Bytes(input).Replace(&result)
for match := range matches {
newVal := bytes.ToUpper(match.Content)
match.ReplaceLiteral(newVal)
}
fmt.Println(string(result))
}
Output: number 42 IS THE answer
type RMatch ¶
type RMatch struct {
// The full match text.
Content []rune
// The range of the match in the original text.
Span Span
// Matches for sub-patterns.
Subs RSubs
}
The same as Match but for runes.
Because the compiler can't infer the core type of [text] if we extend it with a slice of runes.
type RReplacement ¶
type RReplacement struct {
RMatch
// contains filtered or unexported fields
}
func (RReplacement) ReplaceFunc ¶
func (r RReplacement) ReplaceFunc(f func([]rune) []rune)
Example ¶
package main
import (
"fmt"
"unicode"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[a-z]+`)
input := []rune("number 42 is the answer")
var result []rune
matches := rex.Runes(input).Replace(&result)
for match := range matches {
match.ReplaceFunc(func(b []rune) []rune {
first := unicode.ToUpper(b[0])
return append([]rune{first}, b[1:]...)
})
}
fmt.Println(string(result))
}
Output: Number 42 Is The Answer
func (RReplacement) ReplaceLiteral ¶
func (r RReplacement) ReplaceLiteral(val []rune)
Example ¶
package main
import (
"fmt"
"unicode"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`\w+`)
input := []rune("number 42 is the answer")
var result []rune
matches := rex.Runes(input).Replace(&result)
for match := range matches {
first := unicode.ToUpper(match.Content[0])
newVal := append([]rune{first}, match.Content[1:]...)
match.ReplaceLiteral(newVal)
}
fmt.Println(string(result))
}
Output: Number 42 Is The Answer
func (RReplacement) ReplaceTemplate ¶
func (r RReplacement) ReplaceTemplate(val []rune)
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := []rune("number 42 is the answer")
var result []rune
matches := rex.Runes(input).Replace(&result)
for match := range matches {
template := []rune(`[$1]`)
match.ReplaceTemplate(template)
}
fmt.Println(string(result))
}
Output: number 42 [is] [the] answer
type RSubs ¶
type RSubs struct {
// contains filtered or unexported fields
}
Matches for sub-patterns.
type Runes ¶
type Runes struct {
// contains filtered or unexported fields
}
func (Runes) Contains ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[0-9]+`)
input := []rune("number 42 is the answer")
contains := rex.Runes(input).Contains()
if contains {
fmt.Println("the rune slice contains a regexp match")
}
}
Output: the rune slice contains a regexp match
func (Runes) Find ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[a-z]+`)
input := []rune("never gonna give you up")
matches := rex.Runes(input).Find()
for match := range matches {
fmt.Println(match.Span.Start, string(match.Content))
}
}
Output: 0 never 6 gonna 12 give 17 you 21 up
func (Runes) Replace ¶
func (b Runes) Replace(res *[]rune) iter.Seq[RReplacement]
Example ¶
package main
import (
"fmt"
"unicode"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`\w+`)
input := []rune("number 42 is the answer")
var result []rune
matches := rex.Runes(input).Replace(&result)
for match := range matches {
first := unicode.ToUpper(match.Content[0])
newVal := append([]rune{first}, match.Content[1:]...)
match.ReplaceLiteral(newVal)
}
fmt.Println(string(result))
}
Output: Number 42 Is The Answer
type SReplacement ¶
func (SReplacement) ReplaceFunc ¶
func (r SReplacement) ReplaceFunc(f func(string) string)
func (SReplacement) ReplaceLiteral ¶
func (r SReplacement) ReplaceLiteral(val string)
Example ¶
package main
import (
"fmt"
"strings"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := "number 42 is the answer"
var result string
matches := rex.String(input).Replace(&result)
for match := range matches {
newVal := strings.ToUpper(match.Content)
match.ReplaceLiteral(newVal)
}
fmt.Println(string(result))
}
Output: number 42 IS THE answer
func (SReplacement) ReplaceTemplate ¶
func (r SReplacement) ReplaceTemplate(val string)
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := "number 42 is the answer"
var result string
matches := rex.String(input).Replace(&result)
for match := range matches {
template := string(`[$1]`)
match.ReplaceTemplate(template)
}
fmt.Println(string(result))
}
Output: number 42 [is] [the] answer
type String ¶
type String struct {
// contains filtered or unexported fields
}
func (String) Contains ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[0-9]+`)
input := "number 42 is the answer"
contains := rex.String(input).Contains()
if contains {
fmt.Println("the string contains a regexp match")
}
}
Output: the string contains a regexp match
func (String) Find ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`[a-z]+`)
input := "never gonna give you up"
matches := rex.String(input).Find()
for match := range matches {
fmt.Println(match.Span.Start, match.Content)
}
}
Output: 0 never 6 gonna 12 give 17 you 21 up
func (String) Replace ¶
func (s String) Replace(res *string) iter.Seq[SReplacement]
Example ¶
package main
import (
"fmt"
"strings"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`(is|the)`)
input := "number 42 is the answer"
var result string
matches := rex.String(input).Replace(&result)
for match := range matches {
newVal := strings.ToUpper(match.Content)
match.ReplaceLiteral(newVal)
}
fmt.Println(result)
}
Output: number 42 IS THE answer
type Subs ¶
type Subs[T text] struct {
// contains filtered or unexported fields
}
Matches for sub-patterns.
func (Subs[T]) At ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`([a-z.]+)@([a-z.]+)`)
input := "my email is [email protected], text me"
matches := rex.String(input).Find()
for match := range matches {
username := match.Subs.At(1).Content
domain := match.Subs.At(2).Content
fmt.Printf("username: %s; domain: %s", username, domain)
}
}
Output: username: mail; domain: example.com
func (Subs[T]) Iter ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`([a-z.]+)@([a-z.]+)`)
input := "my email is [email protected], text me"
matches := rex.String(input).Find()
for match := range matches {
for sub := range match.Subs.Iter() {
fmt.Println(sub.Content)
}
}
}
Output: [email protected] mail example.com
func (Subs[T]) Slice ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func main() {
rex := regexer.New(`([a-z.]+)@([a-z.]+)`)
input := "my email is [email protected], text me"
matches := rex.String(input).Find()
for match := range matches {
subs := match.Subs.Slice()
username := subs[1].Content
domain := subs[2].Content
fmt.Printf("username: %s; domain: %s", username, domain)
}
}
Output: username: mail; domain: example.com
Click to show internal directories.
Click to hide internal directories.