MySQL searching using regular expression

Explain the basic character matching using REGEXP in MySQL.

REGEXP can be used to match the input characters with the database.

Example:

The following statement retrieves all rows where column employee_name contains the text 1000 (example salary):
Select employee_name From employee Where employee_name REGEXP ‘1000’ Order by employee_name
“.” Can be used to match any single character. “|” can be used to match either of the two strings

Explain how to do matching of several characters at a time in MySQL.

Matching one of several characters:

The set of characters that need to be matched should be enclosed within [ and ].

Example:
Select employee_name From employee Where employee_name REGEXP ‘[105] bon’ Order by employee_name

How do we do matching of special characters in MySQL?

Special characters can be matched by enclosing the character with //.

Example:
Select employee_name From employee Where employee_name REGEXP ‘\\.’ Order by employee_name

What you can use Regular Expression for in MySQL? Support your answer with an example.

Regular expressions in MySql are used in queries for searching a pattern in a string.

1. * Matches 0 more instances of the string preceding it.
2. + matches 1 more instances of the string preceding it.
3. ? Matches 0 or 1instances of the string preceding it.
4. . Matches a single character.
5. [abc] matches a or b or z.
6. | separates strings.
7. ^ anchors the match from the start.

REGEXP can be used to match the input characters with the database.

Example:

The following statement retrieves all rows where column employee_name contains the text 1000 (example salary):
Select employee_name
From employee
Where employee_name REGEXP ‘1000’
Order by employee_name
“.” Can be used to match any single character. “|” can be used to match either of the two strings
MySQL concatenating fields
MySQL concatenating fields - use of Concat() functions
MySQL text manipulation functions
MySQL text manipulation functions - left(), length(), locate(), lower(), LTRIM(), Right(), RTRIM(), Soundex(), Substring(), Upper()
MySQL date time manipulation functions
MySQL date time manipulation functions - AddDate(), AddTime(),CurDate(),CurTime(),Date(), DateDiff(), Date_Add(), Date_format()
Post your comment