
- 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
MySQL Regular expressions: How to match digits in the string with \d?
To match digits in the string, the syntax in MySQL is as follows −
select * from yourTab leName where yourColumnName regexp '[0-9]';
To understand the above syntax, let us create a table −
mysql> create table DemoTable1841 ( Code varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1841 values('John231'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1841 values('19876Sam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1841 values('Carol'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1841 values('67474'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1841;
This will produce the following output −
+----------+ | Code | +----------+ | John231 | | 19876Sam | | Carol | | 67474 | +----------+ 4 rows in set (0.00 sec)
Here is the regular expression to match digit in string −
mysql> select * from DemoTable1841 where Code regexp '[0-9]';
This will produce the following output −
+----------+ | Code | +----------+ | John231 | | 19876Sam | | 67474 | +----------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Finding a Match Within Another Match Java regular expressions
- How to match digits using Java Regular Expression (RegEx)
- How to match only digits in Python using Regular Expression?
- Replace one string with another string with Java Regular Expressions
- Return a specific MySQL string using regular expressions
- How to match whitespace but not newlines using Python regular expressions?
- How to match non-digits using Java Regular Expression (RegEx)
- How to match only non-digits in Python using Regular Expression?
- How to extract data from a string with Python Regular Expressions?
- How to use regular expressions with TestNG?
- Find digits not between the brackets using JavaScript Regular Expressions?
- Replace all words with another string with Java Regular Expressions
- How to match a regular expression against a string?
- How to split a string using regular expressions in C#?
- C# Program to match all the digits in a string
Advertisements