mysql - Regex pattern not working in MySQL when I try to deny the dot
问题描述
I am trying to use a regex in MySQL. I have this expresión [a-zA-Z]^\\.
I supossed the ^
symbol will deny the dot in the expression. If I write a text string with a dot I receive 0 matches but when I write a text string without the dot I also receive 0 matches. For example:
SELECT 'roger' REGEXP '[a-zA-Z]^\\.'
gives me 0 matches. I just need to verify if this expresión ^ denies the dot or not and what am I doing wrong. Thanks in advance.
解决方案
^
only means to exclude characters when it's at the beginning of a [...]
character set. Outside that, it matches the beginning of the string.
If you want to match a non-dot, you should use [^.]
.
SELECT 'roger' REGEXP '[a-zA-Z][^.]'
But since this will match anywhere in the string, it won't work for excluding strings that contain .
. Instead you should reverse the condition:
SELECT 'roger.' NOT REGEXP '[a-zA-Z]\\.'
推荐阅读
- python - 元组元素在列表中的位置
- sql - SQLite / DB 浏览器中的 SQL 查询不返回任何值
- azure-devops - “自动链接此版本中的新作品”和保留政策
- javascript - JS:创建工厂函数而不是类时如何创建原型?
- jasper-reports - 如何使用 JasperReport 6.7.0 在 lineChart 上自定义轴?
- javascript - 我无法在 vue projet 中使用原始 node.js util 模块
- c# - SendGrid V3 使用用户名和密码连接
- python - AWS DLAMI 中的 Pandas np.array 列
- swift - 从多个 UICollectionVIews 内的 UICollectionViewCell 推送新的 UICollectionViewController
- android - 传递自定义对象的数组列表以从 android 响应本机端