0

I am currently struggling with the following input:

# Time: 2022-06-01T20:00:00.000000Z
# User@Host: database[database] @  [10.10.10.10]  Id: 8888888
# Query_time: 0.000450  Lock_time: 0.000160 Rows_sent: 1  Rows_examined: 2
SET timestamp=1654715324;
SELECT id
FROM table_name
WHERE field = 'some-data' AND another_field != 'random-stuff'
ORDER BY field_2;

All my input data will look similar to this. Basically I want to check how many times a certain query shows up. Right now I am a little stuck because my regex cannot filter out the parameters between the single quotes.

I would like to match the following:

SELECT id
FROM table_name
WHERE field = '' AND another_field != ''
ORDER BY field_2;

I've managed to get the query from the input above with the following regExp, but right now this will only match the exact sql.

/(?<=\d;\n).+?(?=;)/gmi

I want to expand this regex so it will ignore anything between single quotes.

Help would be very much appreciated!

  • I'm not entirely sure, but are you looking for something like this? https://stackoverflow.com/a/42048037/2591131 – Eric Jun 08 '22 at 20:14
  • Not necessarily, right now there is an unique identifier but between those single quotes there could be anything. There even could be more than one instance of two single quotes with a variable. – Rick Beumers Jun 08 '22 at 20:23
  • There is a mix of single quotes being used, so with some adjustments, something like this might work: (?<=\`field\` = ').*(?=') – Eric Jun 08 '22 at 21:05
  • Unfortunately that doesn't work for me either. The query could have multiple field the only thing that will be true in any case is that it is quoted in single quotes. I'll update the question with what I would like to match – Rick Beumers Jun 09 '22 at 16:03
  • 1
    I think you need to re-word your question a little and also add in some examples of what you might get and what you expect the result to look like ... that would greatly help with the understanding of what you are trying to achieve. – Eric Jun 12 '22 at 07:00
  • I've updated the question, hope this is more clear. Thanks for the feedback. – Rick Beumers Jun 13 '22 at 12:54

0 Answers0