返回顶部

收藏

The method Regexp#match matches a regular expression against a string.

更多
# If unsuccessful,the method returns nil.
# On success,it returns an instance of class MatchData. 
# And that MatchData object gives you access to all available in formation.

re = /cat/ 
puts re.class # Regexp 

re = /(\d+):(\d+)/ # match a time hh:mm 
md = re.match('Time: 12:34am') 
puts md.class 
puts md[0] 
puts md[1] 
puts md[2] 
puts md.pre_match 
puts md.post_match

标签:Ruby,基础

收藏

0人收藏

支持

0

反对

0

发表评论