/
like_to_rlike.html
58 lines (50 loc) · 1.57 KB
/
like_to_rlike.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<h3>NAME</h3>
like_to_rlike(): Convert a LIKE expression to an RLIKE (REGEXP) expression.
<h3>TYPE</h3>
Function
<h3>DESCRIPTION</h3>
<p>
This function modifies a <strong>LIKE</strong> expression into a compatible expression
to work with <strong>RLIKE</strong> (REGEXP).
</p>
<p>
<strong>LIKE</strong> expressions use "<strong>_</strong>" for single character pattern mapping,
and "<strong>%</strong>" for multiple characters (zero or more) pattern mapping.
</p>
<p>
Regular expressions use "<strong>.</strong>" and "<strong>.*</strong>" instead. The routine
translates to a matching regular expression pattern, while taking care to escape some
(this is incomplete) characters which are special characters in regular expression, that may
have appeared in the <strong>LIKE</strong> expression.
</p>
<h3>SYNOPSIS</h3>
<p>
<blockquote><pre>like_to_rlike(expression TEXT CHARSET utf8)
RETURNS TEXT CHARSET utf8</pre></blockquote>
</p>
<p>
Input:
<ul>
<li><strong>expression</strong>: a <strong>LIKE</strong> expression
</li>
</ul>
</p>
<h3>EXAMPLES</h3>
<blockquote><pre>mysql> SELECT like_to_rlike('customer%');
+----------------------------+
| like_to_rlike('customer%') |
+----------------------------+
| ^customer.*$ |
+----------------------------+
</pre></blockquote>
<blockquote><pre>mysql> SELECT like_to_rlike('c_oun%');
+-------------------------+
| like_to_rlike('c_oun%') |
+-------------------------+
| ^c.oun.*$ |
+-------------------------+
</pre></blockquote>
<h3>ENVIRONMENT</h3>
MySQL 5.1 or newer
<h3>AUTHOR</h3>
Shlomi Noach