MariaDB RLIKE condition

28 February,2020 by Rambler

Question: I'm having a problem  using RLIKE and searching for a hyphen '-'  , within a string.Also some other problems related to identifying  strings with both character and numeric , while excluding numeric only or letters only strings. These are some examples of  the strings:


Example 1 : Digit followed by letter –  12B, 110A , 78B, 2150A, 287H, 941C

Example 2: Numbers or numbers/letter  with   hyphen separator eg  61-63, 98-99, 1-33,2-14,1A-2A,169-173

Example 3: Numbers with forward slash separator e.g 1B/32,142/8 ,336C/2

Could you give me some RLIKE examples for each of the above scenarios

Answer: The following are simple examples to prove the theory. If you need to include these as part of a wider statement then you may need to think about CASE statement 

Example 1 : Digit followed by letter

select '1a' RLIKE '^[0-9][0-9a-z]';

Example 2 : Numbers or numbers/letter  with   hyphen separator

select '1A-2A' RLIKE '[0-9a-z]-[0-9a-z]' ;

Example 3 : Numbers with forward slash separator

select '1A/2A' RLIKE '^[0-9][0-9a-z]*[\/][0-9a-z]$';


Read more on MariaDB

MariaDB Cheatsheet




Author: Rambler (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on MariaDB RLIKE condition