oriser / regroup Goto Github PK
View Code? Open in Web Editor NEWMatch regex group into go struct using struct tags and automatic parsing
License: Apache License 2.0
Match regex group into go struct using struct tags and automatic parsing
License: Apache License 2.0
type SomeModel struct {
SomeItem int64 `regroup"-" `
}
group "-" haven't found in regex
Is your feature request related to a problem? Please describe.
It would be nice if there was a way store whether there was a match into a boolean.
Describe the solution you'd like
I was thinking there could be an additional struct tag to configure this but I am not sure what it should look like. Booleans are currently supported but only to match true or false.
type B struct {
HasSuffixFoo bool `regroup:"foo,flag"`
}
var re = regroup.MustCompile(`.*(?P<foo>foo)?`)
Describe alternatives you've considered
Currently I just check the value of the struct after matching.
Describe the bug
Nothing gets matched to the provided struct in MatchToTarget even though the regex does match
To Reproduce
package main
import (
"fmt"
"github.com/oriser/regroup"
)
const stepNameRegexp = `^(?P<PictureURL>.*/system/(?P<Mentor>.*?)/(.*/)?(?P<Frame>.*)):(?P<Gershon>.*)$`
type stepHandler struct {
vendor string `regroup:"Vendor"`
name string `regroup:"Name"`
imageURL string `regroup:"ImageURL"`
version string `regroup:"Version"`
}
func createStepHandlerFromProto(fullStepName string) (*stepHandler, error) {
r := regroup.MustCompile(stepNameRegexp)
handler := &stepHandler{}
err := r.MatchToTarget(fullStepName, handler)
if err != nil {
fmt.Println(err)
}
return handler, nil
}
func main() {
h, err := createStepHandlerFromProto("i.am.robot/smackplus/system/magic/message/funk:1.1.15")
fmt.Printf("%#v, %s", h, err)
}
Expected behavior
Struct should be filled with the data from the string
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.