0

I am trying to write a regular expression that will match a - (dash), followed by as many letters as it possibly can. What I have at the moment, is the following: exp = (-[a-z A-z]*).
I am getting a SyntaxError: invalid syntax error though.

3
  • 5
    Every regular expression in Python must be placed in a string literal Commented Mar 16, 2016 at 18:35
  • 1
    Please post the full lines of code you are using. Thanks. Commented Mar 16, 2016 at 18:37
  • to expand on @vaultah's comment you need to make the expression a string: exp = "(-[a-z A-z]*)" otherwise you try to define a python expression which doesn't like that syntax. Commented Mar 16, 2016 at 18:43

1 Answer 1

6

try placing your expression in a string

import re
exp = re.compile('(-[a-z A-z]*)')

cheers

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.