SilverViper
SilverViper

Reputation: 679

Get first part of string up to some string, that may or may not be in it

I've got the following strings:

Showname  
Showname - with hyphen  
Showname - Season 4 

What I want is:

Showname     
Showname - with hyphen
Showname

What I've come up with so far is:

/(.*)( - season /d/d?)/i

But that requires - season ?? to be in the string, which is not always the case...

Any help would be really appreciated!

Cheers,
Roy

Upvotes: 0

Views: 247

Answers (1)

mpen
mpen

Reputation: 282795

basically, you want to strip off the season?

do a regex replace on

/ - season \d+$/i

and replace it with an empty string.

if the season isn't in there, nothing will get replaced and the original string will be returned.

Upvotes: 3

Related Questions