List of metacharacters for MySQL regexp square brackets

ε祈祈猫儿з 提交于 2019-11-29 16:37:45

Almost all metacharacters (including the dot ., the +, * and ? quantifiers, the end-of-string anchor $, etc) have no special meaning in character classes, with a few notable exceptions:

  • closing bracket ], for obvious reasons
  • caret ^, which is used to negate the character class (eg: [^ab] matches any character but a and b).
  • hyphen -, which is used to denote a range, (eg: [0-9] matches any digit)

However, these can still be added without escaping if placed in strategic locations within the character class:

  • the closing bracket can be placed right after the opening bracket, eg: []a] matches [ or a.
  • the caret can be placed anywhere but after the opening bracket, eg: [a^] matches ^ or a
  • the hyphen can be placed right after the opening bracket or before the closing bracket, eg: [-a] and [a-] both match a and -.

More information can be found in the man page on POSIX regex (thanks Tomalak Geret'kal!)

From the documentation, right near the top:

This section summarizes, with examples, the special characters and constructs that can be used in MySQL for REGEXP operations. It does not contain all the details that can be found in Henry Spencer's regex(7) manual page. That manual page is included in MySQL source distributions, in the regex.7 file under the regex directory.

Said manpage can be found copied here (thanks, Google!). The information you're looking for is available in there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!