开发者

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

开发者 https://www.devze.com 2023-01-18 04:06 出处:网络
I\'ve got the following strings: Showname Showname - with hyphen Showname - Season 4 开发者_开发技巧

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消