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


advertisement
 

Tip: Using REGEX Case Sensitively

See how to navigate using regex case sensitively in MySQL.


advertisement

WEBINAR:

On-Demand

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


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 |
+ -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- -- +

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date