forked from nalgeon/sqlean
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
45,822 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# regexp: Regular Expressions in SQLite | ||
|
||
Regexp search and replace functions. Based on the [PCRE2](https://github.com/pcre2project/pcre2) engine, this extension supports all major regular expression features (see the section on syntax below). | ||
|
||
Provides the following functions: | ||
|
||
### `REGEXP` statement | ||
|
||
Checks if the source string matches the pattern. | ||
|
||
``` | ||
sqlite> select true where 'the year is 2021' regexp '[0-9]+'; | ||
1 | ||
``` | ||
|
||
### `regexp_like(source, pattern)` | ||
|
||
Checks if the source string matches the pattern. | ||
|
||
``` | ||
sqlite> select regexp_like('the year is 2021', '[0-9]+'); | ||
1 | ||
sqlite> select regexp_like('the year is 2021', '2k21'); | ||
0 | ||
``` | ||
|
||
### `regexp_substr(source, pattern)` | ||
|
||
Returns a substring of the source string that matches the pattern. | ||
|
||
``` | ||
sqlite> select regexp_substr('the year is 2021', '[0-9]+'); | ||
2021 | ||
sqlite> select regexp_substr('the year is 2021', '2k21'); | ||
(null) | ||
``` | ||
|
||
### `regexp_replace(source, pattern, replacement)` | ||
|
||
Replaces all matching substrings with the replacement string. | ||
|
||
``` | ||
sqlite> select regexp_replace('the year is 2021', '[0-9]+', '2050'); | ||
the year is 2050 | ||
sqlite> select regexp_replace('the year is 2021', '2k21', '2050'); | ||
the year is 2021 | ||
``` | ||
|
||
Supports backreferences to captured groups `$1` trough `$9` in the replacement string: | ||
|
||
``` | ||
sqlite> select regexp_replace('the year is 2021', '([0-9]+)', '$1 or 2050'); | ||
the year is 2021 or 2050 | ||
``` | ||
|
||
## Supported syntax | ||
|
||
Basic expressions: | ||
|
||
``` | ||
. any character except newline | ||
a the character a | ||
ab the string ab | ||
a|b a or b | ||
\ escapes a special character | ||
``` | ||
|
||
Quantifiers: | ||
|
||
``` | ||
* 0 or more | ||
+ 1 or more | ||
? 0 or 1 | ||
{n} exactly n | ||
{n,m} between n and m | ||
{n,} n or more | ||
``` | ||
|
||
Groups: | ||
|
||
``` | ||
(...) capturing group | ||
(?:...) non-capturing group | ||
(?>...) atomic group | ||
\N match the Nth captured group | ||
``` | ||
|
||
Character classes: | ||
|
||
``` | ||
[ab-d] one character of: a, b, c, d | ||
[^ab-d] one character except: a, b, c, d | ||
\d one digit | ||
\D one non-digit | ||
\s one whitespace | ||
\S one non-whitespace | ||
\w one word character | ||
\W one non-word character | ||
``` | ||
|
||
Assertions: | ||
|
||
``` | ||
^ start of string | ||
$ end of string | ||
\b word boundary | ||
\B non-word boundary | ||
(?=...) positive lookahead | ||
(?!...) negative lookahead | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
sqlite> .load ./regexp | ||
sqlite> select regexp_like('abcdef', 'b.d'); | ||
``` | ||
|
||
[⬇️ Download](https://github.com/nalgeon/sqlean/releases/latest) • | ||
[✨ Explore](https://github.com/nalgeon/sqlean) • | ||
[🚀 Follow](https://twitter.com/ohmypy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
## PCRE2 LICENCE | ||
|
||
PCRE2 is a library of functions to support regular expressions whose syntax | ||
and semantics are as close as possible to those of the Perl 5 language. | ||
|
||
Releases 10.00 and above of PCRE2 are distributed under the terms of the "BSD" | ||
licence, as specified below, with one exemption for certain binary | ||
redistributions. The documentation for PCRE2, supplied in the "doc" directory, | ||
is distributed under the same terms as the software itself. The data in the | ||
testdata directory is not copyrighted and is in the public domain. | ||
|
||
The basic library functions are written in C and are freestanding. Also | ||
included in the distribution is a just-in-time compiler that can be used to | ||
optimize pattern matching. This is an optional feature that can be omitted when | ||
the library is built. | ||
|
||
## THE BASIC LIBRARY FUNCTIONS | ||
|
||
Written by: Philip Hazel | ||
Email local part: Philip.Hazel | ||
Email domain: gmail.com | ||
|
||
Retired from University of Cambridge Computing Service, | ||
Cambridge, England. | ||
|
||
Copyright (c) 1997-2022 University of Cambridge | ||
All rights reserved. | ||
|
||
## PCRE2 JUST-IN-TIME COMPILATION SUPPORT | ||
|
||
Written by: Zoltan Herczeg | ||
Email local part: hzmester | ||
Email domain: freemail.hu | ||
|
||
Copyright(c) 2010-2022 Zoltan Herczeg | ||
All rights reserved. | ||
|
||
## STACK-LESS JUST-IN-TIME COMPILER | ||
|
||
Written by: Zoltan Herczeg | ||
Email local part: hzmester | ||
Email domain: freemail.hu | ||
|
||
Copyright(c) 2009-2022 Zoltan Herczeg | ||
All rights reserved. | ||
|
||
## THE "BSD" LICENCE | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notices, | ||
this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright | ||
notices, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the University of Cambridge nor the names of any | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. | ||
|
||
## EXEMPTION FOR BINARY LIBRARY-LIKE PACKAGES | ||
|
||
The second condition in the BSD licence (covering binary redistributions) does | ||
not apply all the way down a chain of software. If binary package A includes | ||
PCRE2, it must respect the condition, but if package B is software that | ||
includes package A, the condition is not imposed on package B unless it uses | ||
PCRE2 independently. | ||
|
||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Extracted from the [PCRE2-10.42](https://github.com/PCRE2Project/pcre2/releases/tag/pcre2-10.42) release. |
Oops, something went wrong.