06.11.07

MatchData

Posted in Ruby at 4:56 pm by Željko Filipin

p6090020.jpg

Sapna asked how to extract id from this link.

The solution includes using MatchData. I use it rarely, and I always forget how it is used. So, every time I need it, I have to read documentation. I have decided to make a note here, so I could easily find it later.

This is how you can get href attribute of that link. I will assumed that he knows text (”RE: Check Copy Request”).

This will extract 1303.

2 Comments »

  1. bret said,

    June 12, 2007 at 7:22 am

    Here is another way:

    (ie.link(:text, “RE: Check Copy Request”).href =~ /id=(.*)&/)[1]
    > “1303″

  2. Željko Filipin said,

    June 12, 2007 at 9:44 am

    Thanks Bret. It is nice to know more than one way to do something.

Leave a Comment