RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 2
Title Test Details MySQL Query File
Expression
(?: ""(?:(?:(?:\\.)|[^""\\\r\n])*)""| #double-quoted strings '(?:(?:(?:\\.)|[^'\\\r\n])*)'| #single-quoted strings `(?:(?:(?:\\.)|[^`\\\r\n])*)`| #backticked names (?:\s?(?:\#|--\ ).*(?=[\r\n]))| #hash comments or double-dash comments (?:/\*(?:(?:[^*]|\*(?!/))*)\*/)| #multiline comments (?:[^;`'""](?!(?:--\ |\#|/\*)))* #everything else not quote or followed by comment (?:[^;`'""](?=(?:--\ |\#|/\*)))? #that last possible character before that comment )*
Description
Splits a mysql query file by matching everything but the semicolon at the end. Handles all three comments ("-- ", "#", "/*...*/"), all three quotes (", ', `), and all three line break styles (\r, \n, \r\n). Use with multiline and ignore whitespace/comments.
Matches
load mysql file "share\mysql_fix_privilege_tables.sql" for the full effect
Non-Matches
;
Author Rating: The rating for this expression. Patrick Zahra
Title Test Details MySQL Query Comments and Strings
Expression
("(?:(?:(?:\\.)|[^"\\\r\n])*)"|'(?:(?:(?:\\.)|[^'\\\r\n])*)'|`(?:(?:(?:\\.)|[^`\\\r\n])*)`)|((?:-- .*)|(?:#.*)|(?:/\*(?:(?:[^*]|\*(?!/))*)\*/))
Description
Isolates MySQL Query strings and comments. Lines that look like comments inside strings are not falsely recognised as comments. To strip comments from a MySQL Query, simply replace all matches with group 1
Matches
-- insurance, # renaming some primary keys, /**/, "hello -- this is not a comment"
Non-Matches
ALTER TABLE table_insurance_covered
Author Rating: Not yet rated. Patrick Zahra
   Displaying page 1 of 1 pages; Items 1 to 2

Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials