
- 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
How to search specific word in MySQL with RegExp?
Let us first create a table −
mysql> create table DemoTable -> ( -> Title varchar(255) -> ); Query OK, 0 rows affected (1.82 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John is a good player'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('No,John Doe is not a good player'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Yes,Adam Smith is play cricket match'); Query OK, 1 row affected (0.28 sec) mysql> alter table DemoTable add fulltext(Title); Query OK, 0 rows affected, 1 warning (10.60 sec) Records: 0 Duplicates: 0 Warnings: 1
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------------------------------+ | Title | +--------------------------------------+ | John is a good player | | No,John Doe is not a good player | | Yes,Adam Smith is play cricket match | +--------------------------------------+ 3 rows in set (0.00 sec)
Here is the query to search specific word in MySQL −
mysql> select *from DemoTable -> where Title REGEXP '^.*John.*$';
This will produce the following output −
+----------------------------------+ | Title | +----------------------------------+ | John is a good player | | No,John Doe is not a good player | +----------------------------------+ 2 rows in set (0.11 sec)
- Related Articles
- Search record with a specific value in MySQL using LIKE or REGEXP?
- MySQL query for alphabetical search (ABC) with REGEXP?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- With JavaScript RegExp how to search a string for text that matches regexp?
- How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?
- How to search by specific pattern in MySQL?
- MySQL RegExp to fetch records with only a specific number of words
- Remove specific word in a comma separated string with MySQL
- Find word character in a string with JavaScript RegExp?
- With JavaScript RegExp search a tab character.
- How to search a word by capital or small letter in MySQL?
- MySQL query to search exact word from string?
- ORDER BY a specific word in MySQL
- Search for specific characters within a string with MySQL?
- Find non-word character in a string with JavaScript RegExp

Advertisements