Re: need help of regular expression genius



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

.



Relevant Pages

  • are all expressions an expression?
    ... Only a small part of the queries were translated ... I am now busy to translate manually the queries to T-SQL and that ... are accepted in Access-ADO-mdb but not in Access-ADO-adp. ... expressions, e.g. their use in a WHERE clause: ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Parsing Logical Expressions
    ... translate the user level language to an execution level ... >any faster then just converting the expressions using ... >> translate one syntax to another without doing a complete ...
    (microsoft.public.access.modulesdaovba)
  • Re: OT: Jerry Falwell is dead
    ... for humans to translate accurately from one language to another. ... concepts, expressions, etc. don't translate well. ... Is it hard for God to ... bigger picture than we do, so that what appears unjust to us from our ...
    (rec.music.classical.recordings)
  • Problem with translation
    ... I need translate names medical products from English to Polish. ...
    (sci.med)