Forum: Ruby Regexp simple question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Arun K. (Guest)
on 2009-05-11 18:51
Hi,
   I'm using the following regexp to capture a particular string from a
japanese website content.

/<ul id="ownerProfile" class="owner">.*?<li>([^<]*?)<\/li>/m

The following is the match result.

女性 /

Is there a way I can remove the slash('/') from my result by modifying
the above regular expression.


N. B. gsub can be used but I want to know whether there it can be
achieved by modifying the above regexp

Please help.

Thanks
Arun
7stud -. (Guest)
on 2009-05-11 19:43
In words, describe what just the regex part does.
7stud -. (Guest)
on 2009-05-11 19:45
7stud -- wrote:
> In words, describe what just the regex part does.

I mean the part between the <li> tags.
Srijayanth S. (Guest)
on 2009-05-11 19:46
(Received via mailing list)
Your boss doesn't like gsub?

Try

/<ul id="ownerProfile" class="owner">.*?<li>([^<\/]*?)<\/li>/m


That should work, but it won't work for a case where you have /
separating
something in the inner text.

Jayanth
Phlip (Guest)
on 2009-05-11 20:06
(Received via mailing list)
Arun K. wrote:

>   I'm using the following regexp to capture a particular string from a
> japanese website content.
>
> /<ul id="ownerProfile" class="owner">.*?<li>([^<]*?)<\/li>/m

Parsing HTML with Regexp makes certain baby dieties cry.

Use Nokogiri, with an XPath of '/ul[ @id = "ownerProfile" and @class =
"owner" ]'. Then pull out the .text and you are done!
Srijayanth S. (Guest)
on 2009-05-11 23:41
(Received via mailing list)
That bugle's been blown to death mate.

Jayanth
This topic is locked and can not be replied to.