
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
gopkg.in/phannam1412/go-pattern-matching.v1
Advanced tools
Following are some applications for pattern matching:
input
function sayHello() {
console.log("hello \"world\"");
console.log('how \'are\' you "doing" today');
}
output
function sayHello() {
console.log(_t("hello \"world\""));
console.log(_t('how \'are\' you "doing" today'));
}
Full code
package main
import (
. "github.com/phannam1412/go-pattern-matching/parser"
"strings"
)
func main() {
input := `
function sayHello() {
console.log("hello \"world\"");
console.log('how \'are\' you "doing" today');
}
`
doubleQuote := And(
Text(`"`),
Any(Or(Text(`\"`),NotToken(`"`))),
Text(`"`),
)
singleQuote := And(
Text(`'`),
Any(Or(Text(`\'`),NotToken(`'`))),
Text(`'`),
)
formula := FullSearch(Or(doubleQuote, singleQuote), -1)
tokens := Tokenize(input)
parsed := formula(tokens, 0)
output := input
for _, v := range parsed.Children {
output = strings.ReplaceAll(output, v.Value, "_t(" + v.Value + ")")
}
println(output)
}
input
extract some url from https://example.com
or http://www.w3school.com
or with hyphen http://www.w3-school.com
output
https://example.com
http://www.w3school.com
http://www.w3-school.com
formula
domainName := And(
Alphabet,
Any(And(Hyphen, Alphabet)),
)
formula := FullSearch(And(
Or(Text("http"),Text("https")),
Text("://"),
Any(Text("www.")),
domainName,
Text("."),
Alphabet,
), -1)
input
extract some emails like contact-me-me@yahoo.com, dev.to@gmail.com,
and exclude invalid emails like ^hello@wer.co
output
contact-me-me@yahoo.com
to@gmail.com
hello@wer.co
formula
name := And(Alphabet, Any(And(Hyphen, Alphabet)))
formula := FullSearch(And(name,At,Alphabet,Dot,Alphabet,), -1)
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.