rolandvarga
rolandvarga

Reputation: 126

Match set of string representations of Python complex numbers

I am trying to match a set of complex numbers with re.match(). I am pretty sure the regex should work but still Python doesn't return anything.

pattern = '\.\d+\.\d+\w\.'
value = str(complex(17, 80))
string = '' + value
print(re.match(pattern, string).group())

The output should be something like:

(17+80j) 

But instead it is:

AttributeError: 'NoneType' object has no attribute 'group'

Upvotes: 0

Views: 875

Answers (1)

Alfe
Alfe

Reputation: 59556

Try this:

pattern = r'.\d+.\d+\w.'

Upvotes: 1

Related Questions