My task is to shorten a large SQL query for logging purpose. As such, I need to match a query like this:
INSERT INTO analytics_events (person_id,other_person_id,location_id,location_name,date,action,type,info,created_at,updated_at) VALUES
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
My Regex code is:
Pattern.compile("INSERT(.|\\n)*INTO(.|\\n)*VALUES(.|\\n)*", Pattern.CASE_INSENSITIVE);
Unfortunately, this is causing this exception:
java.lang.StackOverflowError
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3774)
at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
at java.util.regex.Pattern$Loop.match(Pattern.java:4785)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717)
My goal is to convert this SQL text to something that has no data component, such as:
INSERT INTO analytics_events (person_id,other_person_id,location_id,location_name,date,action,type,info,created_at,updated_at)
For the purpose of aggregating timing statistics for queries.