Forum: Ruby on Rails Help with regex needed

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Kim (Guest)
on 2008-10-22 08:58
(Received via mailing list)
Here is the array I am scanning:
["\n<td>&nbsp;<a href=\"/search~S13?/rWR%20121/rwr+121/1,7,9,B/
frameset~2489041&FF=rwr+121&1,1,\">The Academic Writer: A Brief Guide</
a>\n</td>\n<td >\n&nbsp;Ede, Lisa\n</td>\n\n<td >\n&nbsp;Valley
Reserves -- VR 282  -- AVAILABLE\n</td>\n\n<td >\n&nbsp;\n</td>\n\n</
tr>\n<tr>\n<td>&nbsp;<a href=\"/search~S13?/rWR%20121/rwr+121/1,7,9,B/
frameset~1334646&FF=rwr+121&1,1,\">Cultural literacy : what every
American needs to know / E.D. Hirsch, Jr. ; with an appendix, What li</
a>\n</td>\n<td >\n&nbsp;Hirsch, E. D. (Eric Donald), 1928-\n</td>\n
\n<td >\n&nbsp;Valley Reserves -- LC149 .H57 1987  -- AVAILABLE\n</td>
\n\n<td >\n&nbsp;\n</td>]

I am trying to get the values (all but newlines and such) out from in
between the <td> </td>

Tried this :
s.first.scan(/\<td \>(.*?)\<\/td\>/mi)
But I never get the first <td> a href values.

Any help is appreciated. Thanks. Kim
Rob B. (Guest)
on 2008-10-22 09:19
(Received via mailing list)
On Oct 22, 2008, at 12:38 AM, Kim wrote:
> a>\n</td>\n<td >\n&nbsp;Hirsch, E. D. (Eric Donald), 1928-\n</td>\n
> Any help is appreciated. Thanks. Kim
because the first <td> is not a <td > of course.  Your regexp looks for:
  /\<td \>
Did you mean something like %r{<td\b[^>]*>(.*?)</td>}mi

Note that %r{} for a regexp literal can be more convenient when you
hope to match a slash.


Rob B.
This topic is locked and can not be replied to.