[Solved] rearding regex (python) [closed]


Here: http://rubular.com/r/CCW7sAUMrs is an example regex that matches whole text within {{ }}.

You can easily clean up Your string with it using re.sub.

Note, that it will not work when You have text like {{test}} paragraph {{test}}, because it will match whole string.

As larsmans said, it gets harder if You can nest braces. Then it is the job for some kind of Pushdown automaton.

Edit:

Here is the usage:

>>> text = """
... {{ name = name
...     prodcuer =producer
...     writer = writer 
...     language = {{english}}
...     country = USA 
... }}
... Here is text I Need This paragraph.;
... """
>>> import re
>>> exp = "\{\{.+\}\}"
>>> re.sub(exp, "", text, flags=re.S | re.I).strip()
'Here is text I Need This paragraph.;'

1

solved rearding regex (python) [closed]