i have a .sql file which contains the exported code from some database
# Dump File
# Database is ported from MS Access
CREATE DATABASE IF NOT EXISTS `movedb`;
# Table structure for table 'test_prefixSwitchboard Items'
DROP TABLE IF EXISTS `test_prefixSwitchboard Items`;
CREATE TABLE `tbl` (
`x` INTEGER NOT NULL,
`y` INTEGER NOT NULL DEFAULT 0,
`z` VARCHAR(255)
) ENGINE=innodb DEFAULT CHARSET=utf8;
SET autocommit=1;
#
# Dumping data for table 'Switchboard Items'
#
INSERT INTO `tbl` ( `x`, `y`, `z`) VALUES ( '111' , '111' ,'111');
INSERT INTO `tbl` ( `x`, `y`, `z`) VALUES ( '222' , '2222' ,'222');
INSERT INTO `tbl` ( `x`, `y`, `z`) VALUES ( '333' , '333' ,'333');
i want to put it’s values into my database , my column names are diferent from .sql file column names so i need to only extract the values i.e
'111' , '111' ,'111'
'222' , '2222' ,'222'
'333' , '333' ,'333'
and there might be some other tables in that file so its important to get this table only .
i usually don’t ask question without providing any code of my own , but i suck at regex stuff and this seems very complected at least to me.
i have to add , someone is going to uupload this file every couple of day . and i want to add some values to current values before inserting them on my database so i’m more comfortable to use regex
You can match the
VALUES (portion, then capture the text from then on until you hit);and the end of the string, like this:This will print:
Edit: For table names, you would add the table name to the regex, then churn through the column names since you don’t care about capturing them like this:
Where you can change
tblto anything you need.