Re: text processing problem

2005-04-08 Thread Leif K-Brooks
Maurice LING wrote: I'm looking for a way to do this: I need to scan a text (paragraph or so) and look for occurrences of " ()". That is, if the text just before the open bracket is the same as the text in the brackets, then I have to delete the brackets, with the text in it. How's this? import

Re: text processing problem

2005-04-08 Thread Matt
Maurice LING wrote: > Matt wrote: > > I'd HIGHLY suggest purchasing the excellent > href="http://www.oreilly.com/catalog/regex2/index.html";>Mastering > > Regular Expressions by Jeff Friedl. Although it's mostly geared > > towards Perl, it will answer all your questions about regular > > express

Re: text processing problem

2005-04-07 Thread Paul McGuire
Maurice - Here is a pyparsing treatment of your problem. It is certainly more verbose, but hopefully easier to follow and later maintain (modifying valid word characters, for instance). pyparsing implicitly ignores whitespace, so tabs and newlines within the expression are easily skipped, withou

Re: text processing problem

2005-04-07 Thread Maurice LING
Matt wrote: I'd HIGHLY suggest purchasing the excellent http://www.oreilly.com/catalog/regex2/index.html";>Mastering Regular Expressions by Jeff Friedl. Although it's mostly geared towards Perl, it will answer all your questions about regular expressions. If you're going to work with regexs, this

Re: text processing problem

2005-04-07 Thread Matt
Maurice LING wrote: > Matt wrote: > > > > > > Try this: > > import re > > my_expr = re.compile(r'(\w+) (\(\1\))') > > s = "this is (is) a test" > > print my_expr.sub(r'\1', s) > > #prints 'this is a test' > > > > M@ > > > > Thank you Matt. It works out well. The only think that gives it problem >

Re: text processing problem

2005-04-07 Thread Maurice LING
Matt wrote: Try this: import re my_expr = re.compile(r'(\w+) (\(\1\))') s = "this is (is) a test" print my_expr.sub(r'\1', s) #prints 'this is a test' M@ Thank you Matt. It works out well. The only think that gives it problem is in events as "there (there)", where between the word and the same

Re: text processing problem

2005-04-07 Thread Matt
Maurice LING wrote: > Hi, > > I'm looking for a way to do this: I need to scan a text (paragraph or > so) and look for occurrences of " ()". That is, if the > text just before the open bracket is the same as the text in the > brackets, then I have to delete the brackets, with the text in it. > >