I've been trying to use regular expressions to remove a part of a string.
Heroes Chapter 91 - Rescue
I need to remove everything after "Chapter -number-", I can't remove everything after "-" because I'm not sure if the title is always gonna be "Heroes" so, if the title is "-New- Spiderman", it'll remove the wrong part. Same goes with the "-", if it removes everything after a "-", it might remove the wrong part. It has to be "Chapter -number-". I don't know if I explained it well.
However, I've tried doing it like this:
title = "Heroes Chapter 91 - Rescue"
title = re.sub('Chapter \d+ (\D+)', '', title)
but it returns Heroes
.
title = "Heroes Chapter 91 - Rescue"
title = re.sub('Chapter (\d+).*', '', title)
but it returns Heroes
, again.
Any ideas?
PD: Someone linked me to this question but I can't find the solution there, if someone sees it, please point it out. I'm clearly not an expert :)
Final solution:
title = "Heroes Chapter 91 - Rescue"
title = re.sub('(Chapter \d+).*', '\\1', title)