Regular Expression

Paul McGuire ptmcg at austin.rr.com
Tue Oct 23 11:03:39 EDT 2007


On Oct 22, 5:29 pm, patrick.wa... at gmail.com wrote:
> Hi,
>
> I'm trying to learn regular expressions, but I am having trouble with
> this.  I want to search a document that has mixed data; however, the
> last line of every entry has something like C5H4N4O3 or CH5N3.ClH.
> All of the letters are upper case and there will always be numbers and
> possibly one .
>
> However below only gave me none.
>
> import os, codecs, re
>
> text = 'C:\\text_samples\\sample.txt'
> text = codecs.open(text,'r','utf-8')
>
> test = re.compile('\u+\d+\.')
>
> for line in text:
>     print test.search(line)

If those are chemical symbols, then I guarantee that there will be
lower case letters in the expression (like the "l" in "ClH").

-- Paul




More information about the Python-list mailing list