0

I'm trying to create a phone regex, based on a pattern provided in another stack overflow question.

This is the syntax I used to create it in Python:

def phoneRegex = r'^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$'

However, when running this code I get the error:

^ SyntaxError: invalid syntax

What am I doing wrong? Do I need to escape the characters somehow?

Community
  • 1
  • 1
Oved D
  • 7,132
  • 10
  • 47
  • 69

1 Answers1

7

It's the def statement. Take it out. You use def to define functions. That's not a function, that's an assignment of a string.

kindall
  • 178,883
  • 35
  • 278
  • 309