Split

L

Lee Jarvis

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
 
G

Gregory Seidman

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

--Greg
 
P

Phlip

Gregory said:
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... (-;
 
W

William James

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"]
 
A

Arindam Goswami

Lee said:
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.
 
L

Lee Jarvis

Arindam said:
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..
 
W

William James

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?
 
A

Arindam Goswami

Lee said:
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
 
A

Arindam Goswami

This one is better--

f.split(/<\/b>, <b>|<\/*b>,*/)

but it leaves you with one blank cell
 
L

Lee Jarvis

William said:
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 helpful solution..

Thank you all
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,369
Latest member
Carmen32T6

Latest Threads

Top