wood burning stoves 2.0*
The moose likes JDBC and the fly likes Escape Special Character in Mysql Regexp Search Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Escape Special Character in Mysql Regexp Search" Watch "Escape Special Character in Mysql Regexp Search" New topic
Author

Escape Special Character in Mysql Regexp Search

shreya vinay
Greenhorn

Joined: Sep 02, 2005
Posts: 6
Hi,

I need to search for exact match of c++, so escaped it with backslash
and used regexp wordboundries like this

SELECT * FROM tablename j where j.fieldname REGEXP '[[:<:]](C\\+\\+)[:>:]]'
It is not displaying any result. But if i search with this syntax
SELECT * FROM tablename j where j.fieldname REGEXP 'C\\+\\+'
It displays all results other than exact match like VC++ which i dont need.

I guess problem with escape ++ and regexp exact match. Please suggest me a solution for this.

Thanks in advance,
Shreya.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

How about:

SELECT * FROM tablename j where j.fieldname REGEXP '^C\\+\\+$'

The '^' matches start-of-expression, and '$' matches end-of-expression.


JBoss In Action
shreya vinay
Greenhorn

Joined: Sep 02, 2005
Posts: 6
Hi,

Thank you so much for the query. It works well for c++ but it is not working for some words like .net, c#. i need exact match for this also.can you please suggest a solution for these words?

Best Regards,
Shreya.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
The chances of a regex for .c++ matching .net are not very good. Suggest you write what you think would match, please.
 
Don't get me started about those stupid light bulbs.
 
subject: Escape Special Character in Mysql Regexp Search