Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Escape Special Character in Mysql Regexp Search

 
shreya vinay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about:

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

The '^' matches start-of-expression, and '$' matches end-of-expression.
 
shreya vinay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50182
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The chances of a regex for .c++ matching .net are not very good. Suggest you write what you think would match, please.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic