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 '23, 03:23

Baron's gravatar image

Baron
2.1k134147176
accept rate: 46%

edited 19 Apr '23, 03:25


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

permanent link

answered 19 Apr '23, 09:51

Martin's gravatar image

Martin
9.0k130169257
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 '23, 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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×69
×7

question asked: 19 Apr '23, 03:23

question was seen: 751 times

last updated: 19 Apr '23, 10:14