Remove Season and Episode number from title but then return title with episode

Hi, I need to remove Season/Number/Episode from an title of the show.

$title = "Somehthing S01 E01"

$title = "Somehthing2 new work [Wake up] S01E01"

I try below code which works with S01E01 bit not with S01 E01

$title = [regex]::Split($title, '.(\d{1,3})(X|x|E|e)(\d{1,3})')[0]

I would like to convert above title into something like this

  • Somehthing Part 1
  • Somehthing2 new work [Wake up] Part 1

If you file names always follow the rule to have the season with a two digit number you could use a replace like this:

"Somehthing S01 E01" -replace '(?<=\s)S\d{2}(?=\s*E\d{2})' 
"Somehthing2 new work [Wake up] S01E01" -replace '(?<=\s)S\d{2}(?=\s*E\d{2})'


I need to get the Episode number and onvert that number into something like this. Part 1

All of the file are named as S01 E01 or S01E01

I dont think I have any file which is named as S1 E01 or S1 E1


Did you try the code snippet?

[quote quote=291058]Did you try the code snippet?

I did but but it get results as Somehthing E01 which I can do it with my code. I need somthing which convert this into e.g.

Somehthing Part 1

How about replacing “E” with the string "Part " and removing any leading zero from what’s following “E”? … you may read up about the replacement operators of Powershell.

Are the numbers always at the end? If so, this should work:

"Something2 new work [Wake up] S01E01" -replace 'S\d{2}\s?E[0]?([1-9]$|[1-9][0-9]$)','Part $1'
Something2 new work [Wake up] Part 1
"Something2 new work [Wake up] S01 E23" -replace 'S\d{2}\s?E[0]?([1-9]$|[1-9][0-9]$)','Part $1'
Something2 new work [Wake up] Part 23

Break Down:

S\d{2} matches S followed by 2 digits
\s? matches an optional space
E[0]? matches E followed by an optional zero
([1-9]$|[1-9][0-9]$) this is a capture group matching 1-9 or 10-99

By using a capture group, we can refer to it in the second part of the replace. We will get two matches $0 will refer to the full match (S01E01), $1 will refer to the first capture group (just the episode number).

Thank you this works fine.


Don’t you feel like you just did someones homework now? :wink: