Regex: allow full match
This commit is contained in:
parent
ef82e20df5
commit
9ecbbdd977
2 changed files with 27 additions and 1 deletions
|
|
@ -181,7 +181,9 @@ func (p *Pipeline) Process(in []byte) ([]byte, error) {
|
|||
|
||||
if p.re != nil {
|
||||
m := p.re.FindSubmatch(b)
|
||||
if len(m) > 1 {
|
||||
if len(m) == 1 {
|
||||
b = m[0] // full match
|
||||
} else if len(m) > 1 {
|
||||
b = m[1] // first submatch
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
provider/pipeline/pipeline_test.go
Normal file
24
provider/pipeline/pipeline_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package pipeline
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRegex(t *testing.T) {
|
||||
for _, re := range []string{`([0-9.]+)`, `[0-9.]+`} {
|
||||
p, err := new(Pipeline).WithRegex(re)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
res, err := p.Process([]byte("12.3W"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if exp := []byte("12.3"); !bytes.Equal(res, exp) {
|
||||
t.Errorf("Expected %s, got %s", exp, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue