dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Expertise: Intermediate
Jul 3, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Using REGEX Case Sensitively

Consider a table with data as below.

+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
| ID | FIRSTNAME | LASTNAME |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
| 1 | Brian | White |
| 2 | Sian | Greg |
| 3 | Harley | Jeo |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +

Now, let us use regular expression in MySQL to find out the data where the FIRSTNAME starts with the letter 'B'

Query: SELECT * FROM EMP_DETAILS WHERE FIRSTNAME REGEXP '^B';Output:

+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
| ID | FIRSTNAME | LASTNAME |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
| 1 | Brian | White |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +

Below is an example of how to find records that end with the letter 'o'

Query: SELECT * FROM EMP_DETAILS WHERE LASTNAME REGEXP 'o$';Output:

+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
| ID | FIRSTNAME | LASTNAME |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
| 3 | Harley | Jeo |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +
Srinath MS
 
Thanks for your registration, follow us on our social networks to keep up-to-date