https://github.com/jille/deregexp
Deregexp deconstructs a regexp to an expression with substring filters.
https://github.com/jille/deregexp
deconstructor golang regexp
Last synced: over 1 year ago
JSON representation
Deregexp deconstructs a regexp to an expression with substring filters.
- Host: GitHub
- URL: https://github.com/jille/deregexp
- Owner: Jille
- License: bsd-2-clause
- Created: 2020-03-16T21:34:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-27T12:52:02.000Z (over 5 years ago)
- Last Synced: 2025-01-22T12:45:49.226Z (over 1 year ago)
- Topics: deconstructor, golang, regexp
- Language: Go
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deregexp
[](https://godoc.org/github.com/Jille/deregexp)
[](https://travis-ci.org/Jille/deregexp)
Deregexp converts a regexp to an expression with substring matches. This expression does not express exactly the same as the regexp, but a superset. It can be used for a cheap first pass filter, or for index lookups.
## Examples
```shell
$ go run cmd/test/test.go "Mary.+had.+a.+little.+(lamb|sheep)"
"little" AND "Mary" AND "had" AND ("sheep" OR "lamb")
```
Note that the "a" has been dropped because it is implied by "Mary" and "had".
```shell
$ go run cmd/test/test.go "Mary.+had.+(a|no).+little.+(lamb|sheep)"
"little" AND "Mary" AND "had" AND ("sheep" OR "lamb")
```
Note that the "(a|no)" has been dropped because the "a" is implied by "Mary" and "had", and `(TRUE OR "no")` is always true.
## Known limitations
Case insensitivity is not supported. You can of course use the resulting expression case insensitively, but controlling case sensitivity with `(?i)` is not supported. Patches are welcome.