Pattern match: letter repeats : Patterns « Regular Expression « SQL / MySQL






Pattern match: letter repeats

    
/*
mysql> select * from Bird;
+----------+-------+---------+------+------------+------------+
| name     | owner | species | sex  | birth      | death      |
+----------+-------+---------+------+------------+------------+
| BlueBird | Joe   | Car     | f    | 1999-03-30 | NULL       |
| RedBird  | Yin   | Bus     | m    | 1979-04-30 | 0000-00-00 |
| RedBird  | Yin   | Bus     | m    | 1998-01-30 | NULL       |
+----------+-------+---------+------+------------+------------+
3 rows in set (0.00 sec)

mysql> /* '{n}' 'repeat-n-times' operator: */
mysql> SELECT * FROM Bird WHERE name REGEXP '^.{5}$';
Empty set (0.00 sec)


*/  
  
Drop table Bird;

CREATE TABLE Bird (
    name VARCHAR(20), 
    owner VARCHAR(20),
    species VARCHAR(20), 
    sex CHAR(1), 
    birth DATE, 
    death DATE
);
  
INSERT INTO  Bird VALUES ('BlueBird','Joe','Car','f','1999-03-30',NULL);
INSERT INTO  Bird VALUES ('RedBird','Yin','Bus','m','1979-04-30',1998-01-30);
INSERT INTO  Bird VALUES ('RedBird','Yin','Bus','m','1998-01-30',NULL);
  
select * from Bird;

/* '{n}' 'repeat-n-times' operator: */

SELECT * FROM Bird WHERE name REGEXP '^.{5}$';

           
         
    
    
    
  








Related examples in the same category

1.Pattern match: string has 5 characters
2.Pattern in Where clause
3.Using Pattern Matching
4.Pattern Matching
5.Show records where the name matches a search pattern
6.Matching Pattern Metacharacters Literally
7.To match a literal instance of a SQL pattern metacharacter, precede it with a backslash:
8.To make a pattern match case sensitive, use a binary string for either operand
9.Pattern Matching with Regular Expressions