Antony
Antony

Reputation: 4364

Find http:// in string where not preceded by a space

I am looking for a regex for MySQL which will find a row where the following:

Will match: this is texthttp:// and no space before http

Won't match: this is text http:// but has a space so is happy

I tried WHERE message REGEXP '[\s]http:' and for some reason this found some but I know its not all the instances. Thanks

Upvotes: 1

Views: 74

Answers (1)

steffen
steffen

Reputation: 17018

Match strings containing a 'nonspace' character before http://:

regexp '[^[:space:]]http://';

See mysql regexp documentation.

mysql> select * from test;
+------------------+
| s                |
+------------------+
| texthttp://text  |
| http://text      |
| text http://text |
| texthttp://      |
| text http://     |
+------------------+
5 rows in set (0.00 sec)

mysql> select * from test where s regexp '[^[:space:]]http://';
+-----------------+
| s               |
+-----------------+
| texthttp://text |
| texthttp://     |
+-----------------+
2 rows in set (0.00 sec)

Regular expression visualization

SQLFiddle

Upvotes: 2

Related Questions