Is it possible to look for a specific text and distinguish whether the matched text exists in a comment?

Something like this:

select 'really found' where 'select * from ABC;' like '%ABC%';
select 'found only in comments' where 'select * from mytable;--other table than ABC' like '%ABC%';
this works, but I want to prevent this working:
select 'really found' where 'select * from mytable;--other table than ABC' like '%ABC%';
select 'found only in comments' where 'select * from ABC;' like '%ABC%';

asked 19 Apr, 03:23

Baron's gravatar image

accept rate: 46%

edited 19 Apr, 03:25

have you checked the REGEXP search condition to solve the match inside a comment? Eventually using --.*?ABC.*?

permanent link

answered 19 Apr, 09:51

Martin's gravatar image

accept rate: 14%

I guess it should also be considered that a new line ends a "--comment" or "// comment" so text in the next line up to the next comment indicator must be recognized as non-comment - which should work with according REGEXP expressions when adding '\n', too.

(19 Apr, 10:13) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 19 Apr, 03:23

question was seen: 408 times

last updated: 19 Apr, 10:14