Database Reference
In-Depth Information
▼
Output
+--------------+
| prod_name |
+--------------+
| .5 ton anvil |
| 1 ton anvil |
| 2 ton anvil |
+--------------+
▼
Analysis
Here the regular expression
[1-5] Ton
was used.
[1-5]
defines a range, and
so this expression means
match
1
through
5
, and so three matches were returned.
.5 ton
was returned because
5 ton
matched (without the
.
character).
The regular expression language is made up of special characters that have spe-
cific meanings. You've already seen
.
,
[]
,
|
, and
-
, and there are others, too.
Which begs the question, if you needed to match those characters, how would
you do so? For example, if you wanted to find values that contain the
.
char-
acter, how would you search for it? Look at this example:
▼
Input
SELECT vend_name
FROM vendors
WHERE vend_name REGEXP '.'
ORDER BY vend_name;
▼
Output
+----------------+
| vend_name |
+----------------+
| ACME |
| Anvils R Us |
| Furball Inc. |
| Jet Set |
| Jouets Et Ours |
| LT Supplies |
+----------------+
▼
Analysis
That did not work.
.
matches any character, and so every row was retrieved.