At 09:44 AM 9/13/2005, Atilla Ozgur wrote:
parantheses gives you what is matched. for example you have something like
this.
(\d\d)-(\d) if this expression matches to 25-1
$1 gives you 25, $2 gives you 1. Since you have not parantheses in
your regular expression, ruby gives you nil. You find that string but
do not parse it correctly.
in your case i think
$ie.contains_text(/(\/25)/); puts $&
would give you correct answer.
This isn't quite right. Both of you are getting confused.
I suggest that you use IRB to experiment a bit with regular expressions.
irb(main):001:0> sentence = "The rain in spain falls mainly on the plain."
=> "The rain in spain falls mainly on the plain."
irb(main):002:0> sentence =~ /rain/
=> 4
irb(main):003:0> $&
=> "rain"
irb(main):004:0> $1
=> nil
irb(main):005:0> sentence =~ /rain in (spain)/
=> 4
irb(main):006:0> $&
=> "rain in spain"
irb(main):007:0> $1
=> "spain"
$ie.contains_text is completely analogous to the =~ operator, except that
it works with the text of the document.
Bret
_____________________
Bret Pettichord
www.pettichord.com
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general