Match optional end of line after every record with REGEXP?

MySQLMySQLi Database

<p>Let us first create a table &minus;</p><pre class="result notranslate" style="">mysql&gt; 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 &minus;</p><pre class="result notranslate" style="">mysql&gt; insert into DemoTable values(&#39;EMPLOYEE:100 John Smith&#39;); Query OK, 1 row affected (0.18 sec) mysql&gt; insert into DemoTable values(&#39;EMPLOYEE:16537 Chris Brown&#39;); Query OK, 1 row affected (0.10 sec) mysql&gt; insert into DemoTable values(&#39;EMPLOYEE:100 David Miller&#39;); Query OK, 1 row affected (0.12 sec) mysql&gt; insert into DemoTable values(&#39;EMPLOYEE:100 23432 David Miller&#39;); Query OK, 1 row affected (0.20 sec)</pre><p>Display all records from the table using select statement &minus;</p><pre class="prettyprint notranslate">mysql&gt;; select *from DemoTable;</pre><p>This will produce the following output &minus;</p><pre class="result notranslate">+---------------------------------+ | EmployeeCode &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| +---------------------------------+ | EMPLOYEE:100 John Smith &nbsp; &nbsp; &nbsp; &nbsp; | | EMPLOYEE:16537 Chris Brown &nbsp; &nbsp; &nbsp;| | EMPLOYEE:100 David Miller &nbsp; &nbsp; &nbsp; | | 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>&ldquo;EMPLOYEE:100 23432 David Miller&rdquo; &minus;</strong></p><pre class="prettyprint notranslate">mysql&gt; select *from DemoTable where EmployeeCode REGEXP &quot;EMPLOYEE:100([^0-9]|$)&quot;;</pre><p>This will produce the following output &minus;</p><pre class="result notranslate">+---------------------------------+ | EmployeeCode &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| +---------------------------------+ | EMPLOYEE:100 John Smith &nbsp; &nbsp; &nbsp; | | EMPLOYEE:100 David Miller &nbsp; &nbsp; &nbsp; | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 3 rows in set (0.00 sec)</pre>
raja
Updated on 22-Aug-2019 08:00:26

Advertisements