J
Jan Biel
Hi!
I'm trying to split a string into an array of tokens. Some of the tokens are
similar but I don't know how many will be in the string.
Example: (just imagine \n instead of line breaks, this is really one string)
CREATE TABLE personal (
personal_id integer NOT NULL,
vorname varchar(50) NOT NULL,
nachname varchar(50) NOT NULL,
privattelefon varchar(30),
email varchar(130),
datenschutzcode bigint NOT NULL,
CONSTRAINT emailkorrekt_chk CHECK ((email ~~ '%@%'::text))
);
So the string always has a head
"CREATE TABLE personal ("
and a tail
");"
The tokens in between always have the form ".*," except the last one which
is omitting the "," but it is not known beforehand how many tokens exist.
My idea of a fitting perl expression looks like this:
my @table = split /(CREATE TABLE)(.*?)(\()(.*?,)*?(.*?\)
/s, $table;
But it does not work. From the tokens inbetween it only finds
"datenschutzcode bigint NOT NULL,"
and the one after that.
I have tried
my @table = split /(CREATE
TABLE)(.*?)(\()(.*?,)(.*?,)(.*?,)(.*?,)(.*?,)(.*?,)(.*?\)
/s, $table;
Which splits exactly at the correct places. Unluckily with this solution I
have to know the number of tokens beforehand. Additionally I consider it
really bad style.
I hope you can help,
Janbiel
I'm trying to split a string into an array of tokens. Some of the tokens are
similar but I don't know how many will be in the string.
Example: (just imagine \n instead of line breaks, this is really one string)
CREATE TABLE personal (
personal_id integer NOT NULL,
vorname varchar(50) NOT NULL,
nachname varchar(50) NOT NULL,
privattelefon varchar(30),
email varchar(130),
datenschutzcode bigint NOT NULL,
CONSTRAINT emailkorrekt_chk CHECK ((email ~~ '%@%'::text))
);
So the string always has a head
"CREATE TABLE personal ("
and a tail
");"
The tokens in between always have the form ".*," except the last one which
is omitting the "," but it is not known beforehand how many tokens exist.
My idea of a fitting perl expression looks like this:
my @table = split /(CREATE TABLE)(.*?)(\()(.*?,)*?(.*?\)
But it does not work. From the tokens inbetween it only finds
"datenschutzcode bigint NOT NULL,"
and the one after that.
I have tried
my @table = split /(CREATE
TABLE)(.*?)(\()(.*?,)(.*?,)(.*?,)(.*?,)(.*?,)(.*?,)(.*?\)
Which splits exactly at the correct places. Unluckily with this solution I
have to know the number of tokens beforehand. Additionally I consider it
really bad style.
I hope you can help,
Janbiel