Hello,

 

I am working on a way to parse a file and wondered if there is a way to check for multiple patterns. The reason I wonder this is because it would make everything a lot easier regarding calculations on what words to use and so on.

 

What I want to do is to check for two patterns to make sure all occurrences of pattern1 and pattern2 come in the same order as they do in the file I parse. It it contains a number of computer-games I would like the output to look something like this:

PC, Battlefield, Battlefield2

PS2, Battlefield 2: Modern Combat.

 

The file is constructed somewhat similar to this:

PC

            Battlefield, Battfiled2

PS2

            Battlefield 2: Modern Combat

 

Using the following _expression_ (and re.findall) I get somewhat closer:

pattern8 = re.compile(r'search.asp\?title=battlefield.*?><.*?>(PCCD|XBOX 360|XBOX|PLAYSTATION PSP|PLAYSTATION 2) - TITLE<|game.asp\?id=(\d+).*?><.*?><.*?>(.*?)<')

 

The output is:

[('PCCD', '', ''), ('PLAYSTATION 2', '', ''), ('XBOX', '', ''), ('XBOX 360', '', ''), ('PLAYSTATION PSP', '', ''), ('', '4262', ' Battlefield 2: Modern Combat')]

 

I get the last game mentioned in the file, but none of the others.

 

Anybody know how to solve this?

 

Thanks in advance for any help and have a great day!

 

-Kristian

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to