https://github.com/hymkor/exregexp-go
Go package that extends the regexp library with flexible submatch-based string replacement utilities.
https://github.com/hymkor/exregexp-go
go regex-extensions regexp string-replacement utilities
Last synced: about 1 year ago
JSON representation
Go package that extends the regexp library with flexible submatch-based string replacement utilities.
- Host: GitHub
- URL: https://github.com/hymkor/exregexp-go
- Owner: hymkor
- License: mit
- Created: 2025-04-15T16:37:01.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-15T19:14:46.000Z (about 1 year ago)
- Last Synced: 2025-04-15T19:40:22.765Z (about 1 year ago)
- Topics: go, regex-extensions, regexp, string-replacement, utilities
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
exregexp-go
===========
`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 `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
------------
```sh
go get -u github.com/hymkor/exregexp-go
```
Usage
-----
The following example demonstrates how to use `exregexp.ReplaceAllStringSubmatchFunc`:
```example.go
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)
}
```
```go run example.go|
example(123) test(456) hello(789)
```