Re: need help of regular expression genius
- From: "Anthra Norell" <anthra.norell@xxxxxxxxxxxxx>
- Date: Wed, 2 Aug 2006 23:25:48 +0200
Harald,
This works. 's' is your SQL sample.
import SE # From the Cheese Shop with a good manual
Split_Marker = SE.SE (' ";=\<split here>" "~\$_?\$(.|\n)*?\$_?\$~==" ')
s_with_split_marks = Split_Marker (s)
s_split = s_with_split_marks.split ('<split here>')
That's it! And it isn't as complicated as it looks. The first expressions says translate the semicolon to your split mark. The
second expression finds the $-blocks and says translate them to themselves. So they don't change. You can add as many expressions as
you want. You'd probably want to choose a more convenient split mark.
Frederic
----- Original Message -----
From: "GHUM" <haraldarminmassa@xxxxxxxxx>
Newsgroups: comp.lang.python
To: <python-list@xxxxxxxxxx>
Sent: Wednesday, August 02, 2006 5:27 PM
Subject: need help of regular expression genius
I need to split a text at every ; (Semikolon), but not at semikolons
which are "escaped" within a pair of $$ or $_$ signs.
My guess was that something along this should happen withing csv.py;
but ... it is done within _csv.c :(
Example: the SQL text should be splitted at "<split here>" (of course,
those "split heres" are not there yet :)
set interval 2;
<split here>
CREATE FUNCTION uoibcachebetrkd(bigint, text, text, text, text, text,
timestamp without time zone, text, text) RETURNS integer
AS $_$
DECLARE
result int4;
BEGIN
update bcachebetrkd set
name=$2, wieoftjds=$3, letztejds=$4, njds=$5,
konzern=$6, letztespeicherung=$7, betreuera=$8, jdsueberkonzern=$9
where id_p=$1;
IF FOUND THEN
result:=-1;
else
insert into bcachebetrkd (
id_p, name, wieoftjds, letztejds, njds, konzern,
letztespeicherung, betreuera, jdsueberkonzern
)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9);
result:=$1;
END IF;
RETURN result;
END;
$_$
LANGUAGE plpgsql;
<split here>
CREATE FUNCTION set_quarant(mylvlquarant integer) RETURNS integer
AS $$
BEGIN
perform relname from pg_class
where relname = 'quara_tmp'
and case when has_schema_privilege(relnamespace, 'USAGE')
then pg_table_is_visible(oid) else false end;
if not found then
create temporary table quara_tmp (
lvlquara integer
);
else
delete from quara_tmp;
end if;
insert into quara_tmp values (mylvlquarant);
return 0;
END;
$$
LANGUAGE plpgsql;
<split here>
Can anybody hint me in the right direction, how a RE looks for "all ;
but not those ; within $$" ?
Harald
--
http://mail.python.org/mailman/listinfo/python-list
.
- References:
- need help of regular expression genius
- From: GHUM
- need help of regular expression genius
- Prev by Date: Re: Programming newbie coming from Ruby: a few Python questions
- Next by Date: Re: python under earthlink hosting?
- Previous by thread: Re: need help of regular expression genius
- Next by thread: Re: need help of regular expression genius
- Index(es):
Relevant Pages
|