Hsqldb-regular-expressions
提供:Dev Guides
HSQLDB-正規表現
HSQLDBは、正規表現とREGEXP演算子に基づいたパターンマッチング操作のためのいくつかの特別なシンボルをサポートしています。
次のパターンの表は、REGEXP演算子とともに使用できます。
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 |
例
要件を満たすために、さまざまなクエリの例を試してみましょう。 次のクエリをご覧ください。
このクエリを試して、名前が「^ A」で始まるすべての著者を見つけてください。
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'^A.*');
上記のクエリを実行すると、次の出力が表示されます。
+-----------------+
| author |
+-----------------+
| Abdul S |
| Ajith kumar |
+-----------------+
このクエリを試して、名前が「ul $」で終わるすべての著者を見つけます。
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'.*ul$');
上記のクエリを実行すると、次の出力が表示されます。
+-----------------+
| author |
+-----------------+
| John Poul |
+-----------------+
このクエリを試して、名前に「th」が含まれるすべての著者を見つけてください。
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'.*th.*');
上記のクエリを実行すると、次の出力が表示されます。
+-----------------+
| author |
+-----------------+
| Ajith kumar |
| Abdul S |
+-----------------+
このクエリを試して、名前が母音(a、e、i、o、u)で始まるすべての著者を見つけます。
SELECT author FROM tcount_tbl WHERE REGEXP_MATCHES(author,'^[AEIOU].*');
上記のクエリを実行すると、次の出力が表示されます。
+-----------------+
| author |
+-----------------+
| Abdul S |
| Ajith kumar |
+-----------------+