
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Search record with a specific value in MySQL using LIKE or REGEXP?
- MySQL query for alphabetical search (ABC) with REGEXP?
- With JavaScript RegExp how to search a string for text that matches regexp?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- How to search by specific pattern in MySQL?
- With JavaScript RegExp search a tab character.
- MySQL RegExp to fetch records with only a specific number of words
- Find word character in a string with JavaScript RegExp?
- How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?
- Remove specific word in a comma separated string with MySQL
- With JavaScript RegExp search a vertical tab character.
- With JavaScript RegExp search a carriage return character.
- With JavaScript RegExp search an octal number character.
- With JavaScript RegExp search a hexadecimal number character.
- MySQL query to search exact word from string?
Advertisements