
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL regular expression to update a table with column values including string, numbers and special characters
For this, use UPDATE command along with REGEXP. Let us first create a table −
mysql> create table DemoTable2023 -> ( -> StreetNumber varchar(100) -> ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2023 values('7'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2023 values('1'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2023 values('AUS-100'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2023 values('US-101'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2023;
This will produce the following output −
+--------------+ | StreetNumber | +--------------+ | 7 | | 1 | | AUS-100 | | US-101 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to update a table using a regular expression −
mysql> update DemoTable2023 -> set StreetNumber=concat('Street',StreetNumber) -> where StreetNumber regexp'^[0-9]{1,2}$'; Query OK, 2 rows affected (0.19 sec) Rows matched: 2 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable2023;
This will produce the following output −
+--------------+ | StreetNumber | +--------------+ | Street7 | | Street1 | | AUS-100 | | US-101 | +--------------+ 4 rows in set (0.00 sec)
- Related Articles
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Append special characters to column values in MySQL
- MySQL query to retrieve only the column values with special characters?
- Write a Regular Expression to remove all special characters from a JavaScript String?
- MySQL query to remove special characters from column values?
- How to use special characters in Python Regular Expression?
- How can we update MySQL table after padding a string with the values of the column?
- MySQL query to select a specific string with special characters
- How to update a MySQL table by swapping two column values?
- How to use special characters in column names with MySQL?
- How can we update MySQL table after removing a particular string from the values of column?
- MySQL UPDATE column names and set None values with N/A?
- Update existing column data in MySQL and remove the last string from a varchar column with strings and numbers
- MySQL query to replace special characters from column value
- Return only the first 15 characters from a column with string values in MySQL

Advertisements