Gleiche verschachtelte Tags sind egal, die kann ich ja vorher ersetzen. Außerdem macht es ja eigentlich keinen Sinn einen Text doppelt fett darstellen zu wollen.
Wie willst du die denn vorher ersetzen - dafuer schreibst du ja den Parser.... Und was Sinn oder Unsinn macht - das fragst du mal besser deine User. Darueberhinaus gibts tags wo's Sinn macht, zB nested lists oder so. Ausser fuer wirklich kleinere Probleme mit wohlverhaltenden Usern wirst du mit dem regex Ansatz per Definition nicht gluecklich werden koennen. Diez _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
Guten Morgen, Diez B. Roggisch wrote:
Wie willst du die denn vorher ersetzen - dafuer schreibst du ja den Parser....
Ich denke, daß mit 'ersetzen' soetwas gemeint sein könnte:
_________________________________________ import re test = """ ein text, worinnen bbcodes sich tummeln [b][b]naja[u]fetter, unterstrichener text[/u][/b] [/b][c][c]erschendebbes[/c][/c]summeln [b][a][u]FETTER, UNTERSTRICHENER TEXT[/u] [/a]ups[/b]mummeln rummeln[aeh]schrummeln[/aeh] [v]very[v]deep[v]verschachtelt[v]indeed[/v], isnt't[/v] it[/v]?[/v] genuch jez """ def P(text, bbcodes = [], p = re.compile('(.*)(\[(?P<t>.+?)\](.*?)\[/(?P=t)\])(.*)', re.S)): x = '#~§@ß~°' def R(m): if ( m.group(2) ): bbcodes.insert( 0, ( m.group(3), re.sub( x, '[', m.group(2) ), m.start(2) ) ) P( m.group(1) + re.sub( '\[', x, m.group(2) ) + m.group(5), bbcodes ) re.sub( p, R, text ) if not len( bbcodes ): return ['nix da'] return bbcodes for i in P(test): print i _________________________________________ gruß werndt _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
participants (2)
-
Diez B. Roggisch
-
Stephan.Werndt@t-online.de