
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
github.com/rsp/iterex
iter
···re·
ex
Iterator-based regular expressions for Go.
regexp
to iterex
All
to Each
This package is like the standard regexp
with two differences:
-1
)Go 1.23 or higher - the range
keyword accepts iterator functions sice that version:
Detailed documentation:
go get github.com/rsp/iterex
import "github.com/rsp/iterex"`
Instead of:
re := regexp.MustCompile(pattern)
you call:
ir := iterex.MustCompile(pattern)
And instead of:
slice := re.FindAllString(str, -1)
you call:
iterator := re.FindEachString(str)
(limit is optional, defaults to -1
meaning no limit)
Then you can iterate:
for s := range iterator {
fmt.Println(s)
}
iterex
provides lazy version of the "All" receiver functions from
standard regexp
package.
Instead of "All" they have "Each" in their names because instead of returing all results at once, they return iterators that iterate over each result, one at a time.
You can terminate the iteration early by break
ing from the loop.
This package provides 4 ways to compile a pattern,
just like the standard regexp
package:
ir, err := iterex.Compile("...")
ir, err := iterex.CompilePOSIX("...")
ir := iterex.MustCompile("...")
ir := iterex.MustCompilePOSIX("...")
For every regexp
receiver function with All
in the name,
it provides a function with Each
that returns an iterator instead of all results at once.
var b []byte
ir.FindEach(b, n)
- iterator version of re.FindAll(b, n)
ir.FindEachIndex(b, n)
- iterator version of re.FindAllIndex(b, n)
ir.FindEachSubmatch(b, n)
- iterator version of re.FindAllSubmatch(b, n)
ir.FindEachSubmatchIndex(b, n)
- iterator version of re.FindAllSubmatchIndex(b, n)
Note that unlike in regexp
the n
is optional:
ir.FindEach(b)
is the same as ir.FindEach(b, -1)
(no limit)var s string
ir.FindEachString(s, n)
- iterator version of re.FindAllString(s, n)
ir.FindEachStringIndex(s, n)
- iterator version of re.FindAllStringIndex(s, n)
ir.FindEachStringSubmatch(s, n)
- iterator version of re.FindAllStringSubmatch(s, n)
ir.FindEachStringSubmatchIndex(s, n)
- iterator version of re.FindAllStringSubmatchIndex(s, n)
Note that unlike in regexp
the n
is optional:
ir.FindEachString(s)
is the same as ir.FindEachString(s, -1)
(no limit)Rafał Pocztarski - rsp
MIT License (Expat). See LICENSE.md for details.
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.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.