0

I'm trying to take information from a site, read it in line by line and only take the lines that start with two digits, a semicolon, two digits a semicolon and two more digits (i.e. 00:00:00). Matches are exported to another file.

I am getting a syntax error for the semicolons in my regex.

#!/usr/bin/python

import urllib2
import re

#imported urllib to collect the data. imported re for regular expressions to     test format.


#creating our output file
f=open("output.txt", "r+")

#opening a file like object using urllib
webpage= urllib2.open("https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf")


#string used to store the output
str=""

#string used to store current line
temp=""


#add while loop to read in that data. line by line. 
temp=webpage.readline()
if temp.re.search([0-9][0-9]:[0-9][0-9]:[0-9][0-9]):

  str.concat(temp)
  temp=""
8
  • You need to escape the colon by adding a \ infront of it. The colon is an operator in regex. Commented Aug 4, 2015 at 23:19
  • Since when, @blasko? The issue is just missing quotes ("") around the regex. Commented Aug 4, 2015 at 23:29
  • @JakeGriffin helping him with the problem he will encounter once he adds the quotes. Commented Aug 4, 2015 at 23:35
  • My point was that colons are not an operator in regex. "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]" works just fine. Colons are only (part of) an operator in the (?: ... ) syntax. Commented Aug 4, 2015 at 23:39
  • @blasko oh thanks! I also changed code f=open("output.txt", "r+") to w+ however, now I get the error "AttributeError: 'str' object has no attribute 're' from the if line. Commented Aug 4, 2015 at 23:43

1 Answer 1

2

You are searching using raw code, try inputting a string

if temp.re.search("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]"):
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.