Strings that contain a particular substring at any position: : Contains « Regular Expression « SQL / MySQL






Strings that contain a particular substring at any position:

      
mysql>
mysql> CREATE TABLE mytable
    -> (
    ->  name    VARCHAR(20)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO mytable (name)
    ->  VALUES
    ->          ('copper'),
    ->          ('gold'),
    ->          ('iron'),
    ->          ('lead'),
    ->          ('mercury'),
    ->          ('platinum'),
    ->          ('silver'),
    ->          ('tin')
    -> ;
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM mytable;
+----------+
| name     |
+----------+
| copper   |
| gold     |
| iron     |
| lead     |
| mercury  |
| platinum |
| silver   |
| tin      |
+----------+
8 rows in set (0.00 sec)

mysql>
mysql>
mysql> SELECT name FROM mytable WHERE name REGEXP 'er';
+---------+
| name    |
+---------+
| copper  |
| mercury |
| silver  |
+---------+
3 rows in set (0.00 sec)

mysql>
mysql> drop table mytable;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
  








Related examples in the same category

1.String contains
2.Pattern match: string contains
3.Pattern match: contain substring
4.Show records where the name contains a "W"
5.Show records where the name contains a "W" or a "N"
6.Checking Whether a String Contains a Substring
7.Strings that contain a particular substring anywhere:
8.Strings that contain a substring at a specific position
9.Strings that contain a particular substring at a specific position: