By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

syntax incorrect with regex

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
sam wrote:
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?
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

P: n/a
On Fri, 18 Mar 2005 21:57:15 +0800, rumours say that sam <sa*****@authtec.com>
might have written:
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.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #3

P: n/a
On Fri, 18 Mar 2005 21:57:15 +0800, sam <sa*****@authtec.com> wrote:
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,
--
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
Jul 18 '05 #4

P: n/a
"sam" wrote:
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:
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOSE) (no error)
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOSE)

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

</F>

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.