Ruby 正则

(?=re) matches re at this point but does not consume it - you can look

forward for the context of a match without affecting $&.

 

str ="red, white, and blue"
p str.scan(/[a-z]+(?=,)/) 
 the result is :
=> ["red","white"]
 

你可能感兴趣的:(Ruby)