SELECT c, c REGEXP '.', c REGEXP '^', c REGEXP '$' FROM mytable; : REGEXP « Regular Expression « SQL / MySQL






SELECT c, c REGEXP '.', c REGEXP '^', c REGEXP '$' FROM mytable;

      
mysql>
mysql> CREATE TABLE mytable
    -> (
    ->  c       CHAR(1)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO mytable (c)
    ->  VALUES
    ->          ('%'),
    ->          ('_'),
    ->          ('.'),
    ->          ('^'),
    ->          ('$'),
    ->          ('\\')
    -> ;
Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM mytable;
+------+
| c    |
+------+
| %    |
| _    |
| .    |
| ^    |
| $    |
| \    |
+------+
6 rows in set (0.00 sec)

mysql>
mysql> SELECT c, c REGEXP '.', c REGEXP '^', c REGEXP '$' FROM mytable;
+------+--------------+--------------+--------------+
| c    | c REGEXP '.' | c REGEXP '^' | c REGEXP '$' |
+------+--------------+--------------+--------------+
| %    |            1 |            1 |            1 |
| _    |            1 |            1 |            1 |
| .    |            1 |            1 |            1 |
| ^    |            1 |            1 |            1 |
| $    |            1 |            1 |            1 |
| \    |            1 |            1 |            1 |
+------+--------------+--------------+--------------+
6 rows in set (0.00 sec)

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

mysql>

   
    
    
    
    
    
  








Related examples in the same category

1.REGEXP 'e'
2.REGEXP '^ba'
3.REGEXP and CONCAT
4.REGEXP '[abc]'
5.REGEXP 'm.n'
6.REGEXP '[men][men]'
7.POSTCODE REGEXP '[0-9][0-9]*[a-z][a-z]*'
8.NAME REGEXP '^[a-z]{7}'
9.NAME REGEXP '^[a-z]{6,7}$'
10.POSTCODE REGEXP '4{4}'
11.REGEXP '[[.space.]]'
12.REGEXP '[[:<:]]Street[[:>:]]'
13.NAME REGEXP '^n.*e$'
14.REGEXP '[a-z]{9}'
15.Regular expressions do not match NULL values. This is true both for REGEXP and for NOT REGEXP
16.With REGEXP, you need a double backslash to match a metacharacter literally:
17.The primary options that you can use with the REGEXP operator to create expressions in your SQL statements.
18.Be more specific with the REGEXP operator by extending the specified value used by the operator
19.Pattern Matching with REGEXP
20.The command REGEXP offers many more possibilities for formulating a pattern,