Skip to content

hymkor/exregexp-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

exregexp-go

Go Reference Go Test

exregexp-go is a Go package that extends the standard regexp library by providing utilities for flexible string replacement using regular expression submatches.

This package introduces the ReplaceAllSubmatchFunc and the ReplaceAllStringSubmatchFunc function, which allows you to leverage capturing groups for custom replacement logic.

Features

  • Flexible string replacement using capturing groups
  • Simple and intuitive API
  • Built on top of Go's standard regexp library

Installation

go get -u github.com/hymkor/exregexp-go

Usage

The following example demonstrates how to use exregexp.ReplaceAllStringSubmatchFunc:

package main

import (
    "fmt"
    "regexp"

    "github.com/hymkor/exregexp-go"
)

func main() {
    re := regexp.MustCompile(`\b([a-zA-Z]+)(\d+)\b`)
    input := "example123 test456 hello789"
    output := exregexp.ReplaceAllStringSubmatchFunc(re, input, func(submatches []string) string {
        return fmt.Sprintf("%s(%s)", submatches[1], submatches[2])
    })

    fmt.Println(output)
}
example(123) test(456) hello(789)

Author

LICENSE

About

Go package that extends the regexp library with flexible submatch-based string replacement utilities.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages