MySQL 使用正则表达式只获取数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16922248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get only digits using regexp
提问by Oto Shavadze
I have in table column pnum_s
我在表列中 pnum_s
I need get only that rows, which value in column pnum_s
is exactly 10 symbol and all these symbols are only digits
我只需要得到那些行,列中的pnum_s
值正好是 10 个符号,所有这些符号都只是数字
what query must write for this?
必须为此编写什么查询?
I am trying
我在尝试
SELECT * FROM mytable WHERE pnum_s REGEXP '^\d+$'
SELECT * FROM mytable WHERE pnum_s REGEXP '^\d+$'
But this not returns 0 rows
但这不会返回 0 行
回答by RandomSeed
The pattern you are looking for is either '^[0-9]{10}$'
or '^[[:digit:]]{10}$'
.
您正在寻找的模式是'^[0-9]{10}$'
或'^[[:digit:]]{10}$'
。
Everything is in the manual.
一切都在手册中。
回答by rollcona
Check out the reference page.
查看参考页面。
http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp
http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp
What you're looking for is this:
你要找的是这个:
SELECT * FROM mytable WHERE pnum_s REGEXP '^[[:digit:]]{10}$';
回答by danpaq
I think with Mysql you'll want something like this:
我认为使用 Mysql 你会想要这样的东西:
^[[:digit:]]{10}$
回答by Casimir et Hippolyte
try this pattern:
试试这个模式:
'^[0-9]{10}$'