MySQL正则表达式在运行时 [英] MySQL regex at runtime

查看:75
本文介绍了MySQL正则表达式在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT telephone_number
FROM table
WHERE telephone_number REGEXP '^1[() -]*999[() -]*999[() -]*9999$';

我如何使其对于任何数字格式和任何数字均有效 像

how do i make so its valid for any number format and any number like

407-888-0909
1(408)998-7654
7776654433
876-7788

现在它仅对1-999-999-9999有效

right now its only valid for 1-999-999-9999

推荐答案

这是一个简单的MySQL正则表达式,允许在数字分组之间使用某些字符.

Here is a simple MySQL regex that allows certain characters between groupings of numbers.

SELECT telephone_number
FROM table
WHERE telephone_number REGEXP '^1[() -]*999[() -]*999[() -]*9999$';

匹配您的记录,但没有格式化记录,使它们杂乱无章.字符已删除,但您至少可以找到与该数字匹配的记录.

This matches your records but does not format them such that the misc. characters are removed, but you at least can find the records that match the number in question.

通过将其更改为更新语句,可以轻松修复格式.

You could easily fix the formatting by changing this into an update statement.

这篇关于MySQL正则表达式在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆