syntax incorrect with regex

S

sam

Hi,

What is the correct syntax of declaring a regex syntax in Python 2.3?
I got the following error:

# python2.3 test.py
File "test.py", line 10
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS)
^
SyntaxError: invalid syntax

Thanks
sam
 
D

Diez B. Roggisch

sam said:
Hi,

What is the correct syntax of declaring a regex syntax in Python 2.3?
I got the following error:

# python2.3 test.py
File "test.py", line 10
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS)
^
SyntaxError: invalid syntax

No problem here. Is your indentation correct?
 
C

Christos TZOTZIOY Georgiou

macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS)
^
SyntaxError: invalid syntax

Like Diez already said, your problem is probably mixing of tabs with spaces or
bad indentation in general. The "^" character points at the start of your line,
and errors in regular expressions typically raise sre.error, not SyntaxError.

Is this part of a script or does it come from the command line? If the latter,
don't insert any spaces at the start of your line; if the former, compare
indentation with the line above.
 
S

Swaroop C H

Hi,

What is the correct syntax of declaring a regex syntax in Python 2.3?
I got the following error:

# python2.3 test.py
File "test.py", line 10
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS)
^
SyntaxError: invalid syntax

Please check the indentation you have used.
Also, it should be re.VERBOSE (note the ending 'e')

Regards,
 
F

Fredrik Lundh

sam said:
What is the correct syntax of declaring a regex syntax in Python 2.3?
I got the following error:

# python2.3 test.py
File "test.py", line 10
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS)
^
SyntaxError: invalid syntax

compare and contrast:
(no error)
File "<stdin>", line 1
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOSE)
^
SyntaxError: invalid syntax

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,134
Latest member
Lou6777736
Top