

- 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
Match optional end of line after every record with REGEXP?
<p>Let us first create a table −</p><pre class="result notranslate" style="">mysql> create table DemoTable(EmployeeCode varchar(100)); Query OK, 0 rows affected (0.56 sec)</pre><p style="">Insert some records in the table using insert command −</p><pre class="result notranslate" style="">mysql> insert into DemoTable values('EMPLOYEE:100 John Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('EMPLOYEE:16537 Chris Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('EMPLOYEE:100 David Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('EMPLOYEE:100 23432 David Miller'); Query OK, 1 row affected (0.20 sec)</pre><p>Display all records from the table using select statement −</p><pre class="prettyprint notranslate">mysql>; select *from DemoTable;</pre><p>This will produce the following output −</p><pre class="result notranslate">+---------------------------------+ | EmployeeCode | +---------------------------------+ | EMPLOYEE:100 John Smith | | EMPLOYEE:16537 Chris Brown | | EMPLOYEE:100 David Miller | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 4 rows in set (0.00 sec)</pre><p>Following is the query to match optional end of line, for example, 23434 after 100 in <strong>“EMPLOYEE:100 23432 David Miller” −</strong></p><pre class="prettyprint notranslate">mysql> select *from DemoTable where EmployeeCode REGEXP "EMPLOYEE:100([^0-9]|$)";</pre><p>This will produce the following output −</p><pre class="result notranslate">+---------------------------------+ | EmployeeCode | +---------------------------------+ | EMPLOYEE:100 John Smith | | EMPLOYEE:100 David Miller | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 3 rows in set (0.00 sec)</pre>
- Related Questions & Answers
- How to match end of a particular string/line using Java RegEx
- Find a new line character with JavaScript RegExp.
- Match any string with p at the end of it.
- Search record with a specific value in MySQL using LIKE or REGEXP?
- Find the other end point of a line with given one end and mid using C++
- Match any string containing one or more p's with JavaScript RegExp.
- How to match end of the input using Java RegEx?
- MongoDB regular expression to match a specific record?
- How to write a JavaScript RegExp to match an expression?
- Role of CSS :optional Selector
- Append to StringBuilder in C# with a new line on the end
- Find digit with JavaScript RegExp.
- Possible to split a string with separator after every word in JavaScript
- How to match at the end of string in python using Regular Expression?
- Kth smallest element after every insertion in C++
Advertisements