0

Here's my code,

new_name = re.sub(r'[^A-Z a-z]', '', new_name)
new_name += '.txt'

Input: new_name = "Air Supply 85' [1985]"

Output what I am getting: "Air Supply .txt"

It is recognizing the extra spaces too from ' 85' [1985]' But I want it to end the new_name as character only as 'Air Supply.txt'

Yash Agarwal
  • 57
  • 1
  • 6

1 Answers1

1

Trim the whitespace with .strip()

new_name = re.sub(r'[^A-Z a-z]', '', new_name).strip()
new_name += '.txt'

Trimming a string in Python

Community
  • 1
  • 1
Tori Huang
  • 527
  • 1
  • 7
  • 25