# Split

**URL:** <https://rubytalk.org/t/split/40673>\
**Category:** ruby-talk\
**Created:** [17 September 2007 00:03 UTC](https://rubytalk.org/t/split/40673 "2007-09-17T00:03:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@Lee\_Jarvis](https://rubytalk.org/u/Lee_Jarvis)\
**Post date:** [17 September 2007 00:03 UTC](https://rubytalk.org/t/split/40673/1 "2007-09-17T00:03:52Z")

</div>

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/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Lee\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@Lee\_Jarvis](https://rubytalk.org/u/Lee_Jarvis)\
**Post date:** [17 September 2007 00:04 UTC](https://rubytalk.org/t/split/40673/2 "2007-09-17T00:04:38Z")

</div>

Oh, i want all the values inside the \<b\>\</b\> tags, btw

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![W\_James](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@W\_James](https://rubytalk.org/u/W_James)\
**Post date:** [17 September 2007 01:15 UTC](https://rubytalk.org/t/split/40673/3 "2007-09-17T01:15:06Z")

</div>

"\<b\>hi\</b\>, \<b\>there\</b\>, \<b\>fred\</b\>,".scan(/\<b\>(.\*?)\<.b\>/).  
flatten  
&nbsp;&nbsp;&nbsp;&nbsp;==\>["hi", "there", "fred"]

"\<b\>hi\</b\>, \<b\>there\</b\>, \<b\>fred\</b\>,".  
split(%r{\<b\>|\</b\>[,]\*(?:\<b\>)?})  
&nbsp;&nbsp;&nbsp;&nbsp;==\>["", "hi", "there", "fred"]

> **···**
>
> 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

---

<div class="post-metadata">

**Author:** ![Arindam\_Goswami](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Arindam\_Goswami](https://rubytalk.org/u/Arindam_Goswami)\
**Post date:** [17 September 2007 08:23 UTC](https://rubytalk.org/t/split/40673/4 "2007-09-17T08:23:25Z")

</div>

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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![W\_James](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@W\_James](https://rubytalk.org/u/W_James)\
**Post date:** [17 September 2007 08:50 UTC](https://rubytalk.org/t/split/40673/5 "2007-09-17T08:50:08Z")

</div>

Why won't your teacher let you use anything  
other than split?

Does he know that you are getting your answers  
from this forum?

> **···**
>
> 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)

---

<div class="post-metadata">

**Author:** ![Gregory\_Seidman](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Gregory\_Seidman](https://rubytalk.org/u/Gregory_Seidman)\
**Post date:** [17 September 2007 00:44 UTC](https://rubytalk.org/t/split/40673/6 "2007-09-17T00:44:15Z")

</div>

> 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

> **···**
>
> On Mon, Sep 17, 2007 at 09:03:52AM +0900, Lee Jarvis wrote:

---

<div class="post-metadata">

**Author:** ![Lee\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@Lee\_Jarvis](https://rubytalk.org/u/Lee_Jarvis)\
**Post date:** [17 September 2007 08:35 UTC](https://rubytalk.org/t/split/40673/7 "2007-09-17T08:35:05Z")

</div>

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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Lee\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@Lee\_Jarvis](https://rubytalk.org/u/Lee_Jarvis)\
**Post date:** [17 September 2007 13:13 UTC](https://rubytalk.org/t/split/40673/8 "2007-09-17T13:13:33Z")

</div>

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 helpful solution..
> 
> Thank you all  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [17 September 2007 01:00 UTC](https://rubytalk.org/t/split/40673/9 "2007-09-17T01:00:19Z")

</div>

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... (-;

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
> &nbsp;&nbsp;"Test Driven Ajax (on Rails)"  
> &nbsp;&nbsp;assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![Arindam\_Goswami](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Arindam\_Goswami](https://rubytalk.org/u/Arindam_Goswami)\
**Post date:** [17 September 2007 09:15 UTC](https://rubytalk.org/t/split/40673/10 "2007-09-17T09:15:14Z")

</div>

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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Arindam\_Goswami](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Arindam\_Goswami](https://rubytalk.org/u/Arindam_Goswami)\
**Post date:** [17 September 2007 09:36 UTC](https://rubytalk.org/t/split/40673/11 "2007-09-17T09:36:21Z")

</div>

This one is better--

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

but it leaves you with one blank cell

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
