Documentation
¶
Overview ¶
Package regexp gives SQLite the REGEXP operator and regexp functions, with Go's regexp syntax (RE2: no backreferences, and time linear in the text).
sqlite.NewConnector(dsn, regexp.Option())
Then:
x REGEXP pattern 1 if pattern matches somewhere in x, else 0 regexp_like(x, pattern) the same regexp_substr(x, pattern) the first match, or NULL regexp_replace(x, pattern, repl) x with every match replaced
repl takes Go's syntax, not \1: $1 or ${1} is a group by number, ${name} a group by name, and $$ a dollar. A name runs as far as letters, digits and _ go, so write ${1}x, not $1x (a group named 1x). A group that is not there gives the empty text.
A NULL argument gives NULL. A REAL argument is an error: write CAST(x AS TEXT). A pattern that does not compile is the error of the statement.
Example ¶
package main
import (
"database/sql"
"fmt"
"github.com/liustack/sqlite"
"github.com/liustack/sqlite/ext/regexp"
)
func main() {
c, err := sqlite.NewConnector(":memory:", regexp.Option())
if err != nil {
panic(err)
}
db := sql.OpenDB(c)
defer db.Close()
var match bool
var first, swapped string
err = db.QueryRow(`SELECT 'v1.22.3' REGEXP '^v\d+\.\d+\.\d+$',
regexp_substr('order 66 and 99', '\d+'),
regexp_replace('Doe, Jane', '(\w+), (\w+)', '$2 $1')`).Scan(&match, &first, &swapped)
if err != nil {
panic(err)
}
fmt.Println(match, first, swapped)
}
Output: true 66 Jane Doe
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.