Hsqldb 简明教程
HSQLDB - Regular Expressions
HSQLDB 支持一些特殊符号,用于基于正则表达式和 REGEXP 运算符进行模式匹配操作。
HSQLDB supports some special symbols for pattern matching operation based on regular expressions and the REGEXP operator.
以下是模式表,可与 REGEXP 运算符一起使用。
Following is the table of pattern, which can be used along with REGEXP operator.
Pattern |
What the Pattern Matches |
^ |
Beginning of the string |
$ |
End of the string |
. |
Any single character |
[…] |
Any character listed between the square brackets |
[^…] |
Any character not listed between the square brackets |
p1 |
p2 |
p3 |
Alternation; matches any of the patterns p1, p2, or p3 |
* |
Zero or more instances of the preceding element |
+ |
One or more instances of the preceding element |
{n} |
n instances of the preceding element |
{m,n} |
m through n instances of the preceding element |
Example
让我们尝试不同的示例查询来满足我们的要求。查看以下给定的查询。
Let us try different example queries to meet our requirements. Take a look at the following given queries.
试用此查询以查找所有名称以“^A”开头的作者。
Try this Query to find all the authors whose name starts with '^A'.
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'^A.*');
在执行上述查询后,你将收到以下输出。
After execution of the above query, you will receive the following output.
+-----------------+
| author |
+-----------------+
| Abdul S |
| Ajith kumar |
+-----------------+
试用此查询以查找所有名称以“ul$”结尾的作者。
Try this Query to find all the authors whose name ends with 'ul$'.
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'.*ul$');
在执行上述查询后,你将收到以下输出。
After execution of the above query, you will receive the following output.
+-----------------+
| author |
+-----------------+
| John Poul |
+-----------------+
试用此查询以查找所有名称包含“th”的作者。
Try this Query to find all the authors whose name contains 'th'.
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'.*th.*');
在执行上述查询后,你将收到以下输出。
After execution of the above query, you will receive the following output.
+-----------------+
| author |
+-----------------+
| Ajith kumar |
| Abdul S |
+-----------------+
试用此查询以查找所有名称以元音(a、e、i、o、u)开头的作者。
Try this query to find all the authors whose name starts with vowel (a, e, i, o, u).
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'^[AEIOU].*');
在执行上述查询后,你将收到以下输出。
After execution of the above query, you will receive the following output.
+-----------------+
| author |
+-----------------+
| Abdul S |
| Ajith kumar |
+-----------------+