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.
19eb75164135659a8fae98101b1c250e?d=identicon&s=25 Arun Kumar (arun_nss)
on 2009-05-11 16: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
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-11 17:43
In words, describe what just the regex part does.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-11 17:45
7stud -- wrote:
> In words, describe what just the regex part does.

I mean the part between the <li> tags.
1e736afdcdfe0753d67a81d449aca590?d=identicon&s=25 Srijayanth Sridhar (Guest)
on 2009-05-11 17: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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-05-11 18:06
(Received via mailing list)
Arun Kumar 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!
1e736afdcdfe0753d67a81d449aca590?d=identicon&s=25 Srijayanth Sridhar (Guest)
on 2009-05-11 21:41
(Received via mailing list)
That bugle's been blown to death mate.

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