[Python-de] WG: [Python-de] Re: [Python-de] reguläre Ausdrücke
Rene Liebscher
R.Liebscher at gmx.de
Tue Apr 23 19:11:37 EDT 2002
Josef Cihal wrote:
>
> ...es köönte eine Lösung geben,
> nicht optimiert ,zu viele Zeilen,aber es könnte helfen.
>
> import re
>
> src=open("c:\\tmp\\abc.txt","r")
> src_list= src.readlines()
> src.close()
> aBeg=0; dest_list=[]
> for line in src_list:
> if re.match(r"/\*",line) and aBeg==0:
> print "zacatek",line
> aBeg=1
> continue
> if re.match(r".*\*/",line)and aBeg==1:
> print "konec",line
> aBeg=0
> continue
> if aBeg==1:
> print "uvnitr",line
> continue
>
> dest_list.append(line)
> dest = open("c:\\tmp\\abc.txt","w")
> dest.writelines(dest_list)
> dest.close()
>
> Es sucht Beginn: z.B. /*d;jsafjds
> or /*
>
> igrnoriert die und die nöchste Zeile bis Ende gefunden wird:
> z.B. kldshfla*/
> or */
>
Das funktioniert aber nicht wenn folgendes kein Kommentar sein soll:
----------
print "/*"
print "dies ist nicht im Kommentar"
print "*/"
----------
Und darum geht es auch in den anderen Lösungsvorschlägen/diskussionen,
allerdings etwas komplizierter ausgedrückt.
MfG
Rene
More information about the Python-de
mailing list