devxlogo

Using REGEX Case Sensitively

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

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist