regexp_like
1. REGEXP_LIKE Function
=======regexp_like
1. REGEXP_LIKE Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe REGEXP_LIKE function in H2 database is used to check if a given string matches a specified regular expression pattern.
2. Syntax
The syntax for the REGEXP_LIKE function in H2 database is as follows:
REGEXP_LIKE(input_string, regex_pattern)
Arguments
input_string
: The string value that needs to be checked against the regular expression pattern.regex_pattern
: The regular expression pattern that the input string is matched against.
Return
- The REGEXP_LIKE function returns a boolean value:
TRUE
if the input string matches the provided regular expression pattern, andFALSE
otherwise.
3. Notes
- The REGEXP_LIKE function in H2 database follows the Java regular expression syntax.
- The regular expression pattern can contain a combination of characters and special metacharacters to define the pattern matching rules.
- If the input string is
NULL
or the regular expression pattern is empty, the REGEXP_LIKE function will returnNULL
. - Take caution while constructing regular expressions, as incorrect patterns may lead to unexpected results or errors.
4. Examples
Here are a few examples demonstrating the usage of the REGEXP_LIKE function in H2 database:
Example 1 - Checking if a string matches a pattern:
SELECT REGEXP_LIKE('Hello World', '^Hello.*') AS is_match;
Output:
is_match
--------
TRUE
Example 2 - Using a case-insensitive regular expression:
SELECT REGEXP_LIKE('Database', 'database', 'i') AS is_match;
Output:
is_match
--------
TRUE
Example 3 - Checking multiple strings against a pattern:
SELECT name
FROM users
WHERE REGEXP_LIKE(name, '^[A-Za-z]+$');
Output:
name
-----
John
Alice
5. Related Functions
- regexp_replace - Replace matched substrings using a regular expression.
- REGEXP_INSTR - Find the position of a substring matching a regular expression.