2011-07-13 4 views

Répondre

4

Vous n'avez pas besoin d'une expression régulière pour trouver un sous-chaîne fixe, juste include? fera:

"Feed returned error status: There is no row at position 0.".include?("no row at position 0") 
# => true 
1

Pour ce cas spécifique, vous n'avez pas besoin d'une regex. Un simple index fera:

irb(main):001:0> a = "Feed returned error status: There is no row at position 0." 
=> "Feed returned error status: There is no row at position 0." 
irb(main):002:0> a.index("no row at position 0") 
=> 37 

index retournera nil si elle ne trouve pas la chaîne:

irb(main):003:0> a.index("no row at position 0a") 
=> nil 
+0

ah, cool ... merci pour cela – keruilin

Questions connexes