Željko Filipin's blog.
Home Blog Tags License

View on GitHub
11 June 2007


by Željko Filipin

Sapna asked how to extract id from this link.

<a href="MessageDetail.aspx?id=1303&messageToUser=True">
  RE: Check Copy Request

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., "RE: Check Copy Request").href
=> "MessageDetail.aspx?id=1303&messageToUser=True"

This will extract 1303.

m = /id=(1303)/.match(, "RE: Check Copy Request").href)
=> #<matchdata :0x2d147b8>

=> "1303"
tags: code - ruby