如何在Ruby中将季节/剧集与字符串进行匹配?

如何在Ruby中将季节/剧集与字符串进行匹配?,ruby,string,match,Ruby,String,Match,我需要找出当数字未知时,变量是否包含S00E00。我尝试了很多不同的方法,我能识别字母和数字,但只能分别识别。基本上,我需要的是根据此处定义的标准命名来确定文件是否为电视节目:。您可以使用以下表达式: / \b # word boundary s # letter s \d{2} # exactly 2 digits e # letter e \d{2} # exactly 2 digits \b # word boundary /ix

我需要找出当数字未知时,变量是否包含
S00E00
。我尝试了很多不同的方法,我能识别字母和数字,但只能分别识别。基本上,我需要的是根据此处定义的标准命名来确定文件是否为电视节目:。

您可以使用以下表达式:

/
  \b    # word boundary
   s    # letter s
  \d{2} # exactly 2 digits
   e    # letter e
  \d{2} # exactly 2 digits
  \b    # word boundary
/ix     # case- and space-insensitive matching
例如:

str = 'Heroes - s01e02 - The Coming Storm.avi'
str.match /\bs\d{2}e\d{2}\b/i
#=> #<MatchData "s01e02">
str='Heroes-s01e02-即将到来的风暴.avi'
str.match/\bs\d{2}e\d{2}\b/i
#=> #

您可以使用以下表达式:

/
  \b    # word boundary
   s    # letter s
  \d{2} # exactly 2 digits
   e    # letter e
  \d{2} # exactly 2 digits
  \b    # word boundary
/ix     # case- and space-insensitive matching
例如:

str = 'Heroes - s01e02 - The Coming Storm.avi'
str.match /\bs\d{2}e\d{2}\b/i
#=> #<MatchData "s01e02">
str='Heroes-s01e02-即将到来的风暴.avi'
str.match/\bs\d{2}e\d{2}\b/i
#=> #

+1用于分解正则表达式并解释每个组件。+1用于分解正则表达式并解释每个组件。