|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Ok guys im looking for something sexy to split this HTML (This HAS to be
done using split, nothing else) <b>hi</b>, <b>there</b>, <b>fred</b>, I would like to split them values into an array, Is there any chance this can be done? Because im beginning to think there isn't Tia -- Posted via http://www.ruby-forum.com/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
|
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Mon, Sep 17, 2007 at 09:03:52AM +0900, Lee Jarvis wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be > done using split, nothing else) > > <b>hi</b>, <b>there</b>, <b>fred</b>, > > I would like to split them values into an array, Is there any chance > this can be done? Because im beginning to think there isn't > > Oh, i want all the values inside the <b></b> tags, btw str.split(/<b>|<\/b>,|<\/b>, <b>/) > Tia --Greg |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Gregory Seidman wrote:
>> Oh, i want all the values inside the <b></b> tags, btw > > str.split(/<b>|<\/b>,|<\/b>, <b>/) I thought, among other attrocities, that < was a reserved character for regular expressions. Not sure about the "has to be done using .split part", if some of us have studied REXML and Hpricot so thoroughly... (-; -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Sep 16, 7:03 pm, Lee Jarvis <jarv...@gmail.com> wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be > done using split, nothing else) > > <b>hi</b>, <b>there</b>, <b>fred</b>, > > I would like to split them values into an array, Is there any chance > this can be done? Because im beginning to think there isn't "<b>hi</b>, <b>there</b>, <b>fred</b>,".scan(/<b>(.*?)<.b>/). flatten ==>["hi", "there", "fred"] "<b>hi</b>, <b>there</b>, <b>fred</b>,". split(%r{<b>|</b>[, ]*(?:<b>)?}) ==>["", "hi", "there", "fred"] |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Lee Jarvis wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be > done using split, nothing else) > > <b>hi</b>, <b>there</b>, <b>fred</b>, > > I would like to split them values into an array, Is there any chance > this can be done? Because im beginning to think there isn't > > Tia There you go --- f.split(/, |,/) where f is your string. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Arindam Goswami wrote:
> Lee Jarvis wrote: >> Ok guys im looking for something sexy to split this HTML (This HAS to be >> done using split, nothing else) >> >> <b>hi</b>, <b>there</b>, <b>fred</b>, >> >> I would like to split them values into an array, Is there any chance >> this can be done? Because im beginning to think there isn't >> >> Tia > > > There you go --- > f.split(/, |,/) > > where f is your string. Thanks, but i need to values inside the <b> tags, So <b>hello</b> I need hello.. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Sep 16, 7:03 pm, Lee Jarvis <jarv...@gmail.com> wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be > done using split, nothing else) Why won't your teacher let you use anything other than split? Does he know that you are getting your answers from this forum? |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
Lee Jarvis wrote:
> Thanks, but i need to values inside the <b> tags, So <b>hello</b> I need > hello.. Quick and dirty, but it works -- f.split(/, |,/).to_s.split(/<b>/).to_s.split(/<\/b>/) could not figure out how to do this in one split -- Posted via http://www.ruby-forum.com/. |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
This one is better--
f.split(/<\/b>, <b>|<\/*b>,*/) but it leaves you with one blank cell -- Posted via http://www.ruby-forum.com/. |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
William James wrote:
> On Sep 16, 7:03 pm, Lee Jarvis <jarv...@gmail.com> wrote: >> Ok guys im looking for something sexy to split this HTML (This HAS to be >> done using split, nothing else) > > Why won't your teacher let you use anything > other than split? > > Does he know that you are getting your answers > from this forum? Who said it was a teacher, This was for a challenge, And you're not providing an answers, Just a very ful solution.. Thank you all -- Posted via http://www.ruby-forum.com/. |
|
![]() |
| Outils de la discussion | |
|
|