mysql正则表达式字符替换语句
本文章来介绍一下在sql语句中使用正则了,这是我们讲述在mysql中使用mysql正则表达式实例,有需要了解的朋友可以参考一下。
代码如下 | 复制代码 |
update comment set url=IF(url REGEXP 'test.yahoo.com.cn',REPLACE(url,'www1.hzhuti.com','www.sina.com'),REPLACE(url,'www2.yahoo.com','www.sina.com')) where 1=1; |
$ 匹配字符串的结束部分
$sql ="SELECT 'fonfo' REGEXP '^fo$' from string_find";
. 匹配任何字符(包括回车和新行)
$sql ="SELECT 'fofo' REGEXP '^f.*$' from string_find";
a* 匹配0或多个a字符的任何序列
$sql ="SELECT 'Ban' REGEXP '^Ba*n' from string_find";
a+ 匹配1个或多个a字符的任何序列
$sql ="SELECT 'Ban' REGEXP '^Ba+n' from string_find";
a? 匹配0个或1个a字符
$sql ="SELECT 'Bn' REGEXP '^Ba?n' from string_find";
de|abc 匹配序列de或abc
(abc)* 匹配序列abc的0个或多个实例。
{1}, {2,3} {n}或{m,n}符号提供了编写的更通用方式,能够匹配模式的很多前述原子(或“部分”)。m和n均为整数。
o a*
可被写入为a{0,}。
o a+
可被写入为a{1,}。
o a?
可被写入为a{0,1}。
更准确地讲,a{n}与a的n个实例准确匹配。a{n,}匹配a的n个或更多实例。a{m,n}匹配a的m~n个实例,包含m和n。
m和n必须位于0~RE_DUP_MAX(默认为255)的范围内,包含0和RE_DUP_MAX。如果同时给定了m和n,m必须小于或等于
[a-dX], [^a-dX] 匹配任何是(或不是,如果使用^的话)a、b、c、d或X的字符。两个其他字符之间的“-”字符构成一个范围,与从第1个字符开始到第2个字符之间的所有字符匹配。例如,[0-9]匹配任何十进制数字 。要想包含文字字符“]”,它必须紧跟在开括号“[”之后。要想包含文字字符“-”,它必须首先或最后写入。对于[]对内未定义任何特殊含义的任何字符,仅与其本身匹配。
为了说明扩展正则表达式如何工作,上面所示的 LIKE 查询在下面使用 REGEX P重写:
1、为了找出以 “ b ” 开头的名字 , 使用 “ ^ ” 匹配名字的开始并且 “ [bB] ” 匹配小写或大写的 “ b ” :
> SELECT * FROM pet WHERE name REGEXP "^[bB]";
2、为了找出以 “ fy ” 结尾的名字,使用 “ $ ” 匹配名字的结尾:
mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
3、为了找出包含正好 5 个字符的名字,使用 “ ^ ” 和 “ $ ” 匹配名字的开始和结尾 ,和 5 个 “ . ” 实例在两者之间:
mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
4、你也可以使用 “ {n} ”“ 重复 n 次 ” 操作符重写先前的查询:
mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
更多详细内容请查看:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.
