Returns true if the input matches the configured Go regular expression.
| Field | Type | Description |
|---|---|---|
Input | *string | String to test |
| Field | Type | Description |
|---|---|---|
Match | bool | True when input matches pattern |
| Key | Type | Default | Description |
|---|---|---|---|
pattern | string | required | Go regular expression, compiled at setup |
Pattern compiled at setup. Invalid patterns cause a setup error, not a runtime error.
Validates that an email address matches a standard format before passing it to a send step.
package main
import (
"context"
"encoding/json"
"log"
"os"
"time"
"github.com/akennis/sparsi-go/library"
_ "github.com/akennis/dagor/operator/builtin"
"github.com/panjf2000/ants/v2"
"github.com/akennis/dagor"
"github.com/akennis/dagor/graph"
)
func main() {
email := "alice@example.com"
library.RegisterConst("email_val", email)
g, err := graph.NewBuilder("regex_demo").
Vertex("src").Op("email_val").Output("Result", "email_wire").
Vertex("check").Op("IfStringRegexMatchOp").
Params(map[string]string{
"pattern": `^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`,
}).
Input("Input", "email_wire").
Output("Match", "is_valid").
Build()
if err != nil {
log.Fatalf("build: %v", err)
}
pool, err := ants.NewPool(4)
if err != nil {
log.Fatalf("pool: %v", err)
}
defer pool.Release()
eng, err := dagor.NewEngine(g, pool)
if err != nil {
log.Fatalf("engine: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if err := eng.Run(ctx); err != nil {
log.Fatalf("run: %v", err)
}
out := map[string]any{"email": email}
if raw, ok := eng.GetOutput("is_valid"); ok {
out["is_valid_email"] = *raw.(*bool)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(out)
}