I have a script that executes database queries, and I use semi-colons + new line (\n) to separate one query from another. See below:
CREATE TABLE `moxedo`.`mox_config` (`;`, `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT , `group_id` INT(3) UNSIGNED NOT NULL , `is_enabled` INT(1) UNSIGNED NOT NULL , `tag` VARCHAR(255) NOT NULL , `name` VARCHAR(80) NOT NULL , `value` VARCHAR(255) NOT NULL , `description` TEXT NOT NULL , `init_params` TEXT NOT NULL , `datetime_added` DATETIME NOT NULL , `datetime_lastmodified` DATETIME NOT NULL , `timestamp_univ` BIGINT(14) NOT NULL , PRIMARY KEY ( `id` ) )
ENGINE = INNODB;
ALTER TABLE `moxedo`.`mox_config` ADD UNIQUE `ix_u_tag_ge` ( `tag` );
I’m looking for a Regex Pattern that will help me capture each database query. However, I need to also accommodate the occurrence of semi-colons within the query body, as the code above displays.
I’d appreciate some assistance. Thanks in advance.
You can give this a try:
(.*?;)– match everything followed by a semicolon…(?:\s+|$)– followed by whitespace characters or the end of the stringIf there are other use cases where the semicolon can appear on a different position, the regex will need updated accordingly.