Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用REGEX的Mysql选择查询_Mysql_Regex - Fatal编程技术网

使用REGEX的Mysql选择查询

使用REGEX的Mysql选择查询,mysql,regex,Mysql,Regex,我在mysql中使用了一个正则表达式,如下所示 select * from table1 where table1.name REGEXP '[[:<:]]1.1[[:>:]]' 但我只需要匹配1.1 有什么想法吗 select * from table1 where table1.name REGEXP '^1.1$' 确保只允许使用1.1(但也允许使用1X1或111,因为点匹配任何字符-如果要匹配文字点,请使用^1\.1$) 当然,现在有一个问题,为什么要使用正则表达式,因为

我在mysql中使用了一个正则表达式,如下所示

select * from table1 where
table1.name
REGEXP '[[:<:]]1.1[[:>:]]'
但我只需要匹配1.1

有什么想法吗

select * from table1 where
table1.name
REGEXP '^1.1$'
确保只允许使用
1.1
(但也允许使用
1X1
111
,因为点匹配任何字符-如果要匹配文字点,请使用
^1\.1$

当然,现在有一个问题,为什么要使用正则表达式,因为它只是一个匹配的文本字符串,而不是一个变量模式

您的正则表达式失败,因为您正在使用字母数字字符和非字母数字字符(或字符串的开始/结束)之间匹配的单词开始/结束锚,并且由于
[[:>:]
1
之间匹配,正则表达式至少部分匹配了
1.1.1

select * from table1 where
table1.name
REGEXP '^1.1$'