# Suggestion for string parsing

**URL:** <https://rubytalk.org/t/suggestion-for-string-parsing/49150>\
**Category:** ruby-talk\
**Created:** [18 September 2008 08:48 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150 "2008-09-18T08:48:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ema\_Fuma](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Ema\_Fuma](https://rubytalk.org/u/Ema_Fuma)\
**Post date:** [18 September 2008 08:48 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/1 "2008-09-18T08:48:11Z")

</div>

Hi all,  
I would like to know if there's a better way to parse a string and  
assing values to variables;

Ex:

Client=MPEG-4,390000,700000,24000

I can do

line =~ /(\w\*)=([0-9A-Za-z -.:]\*),([0-9]\*),([0-9]\*),([0-9]\*)/

and

var1 = $1  
var2 = $2  
var3 = $3  
var4 = $4  
var4 = $5

But I'm sure there's a better way, even considering that the number of  
parameters can increase and I don't want to write a long regular  
expression rule, that is hard to read.

Thanks a lot for any tips

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

---

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [18 September 2008 09:06 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/2 "2008-09-18T09:06:59Z")

</div>

# var1 = $1  
# var2 = $2  
# var3 = $3  
# var4 = $4  
# var5 = $5

hint: array

eg,

> line

=\> "Client=MPEG-4,390000,700000,24000"

> re

=\> /(\w\*?)=([0-9A-Za-z -.:]\*?),(\d\*?),(\d\*?),(\d\*)/

> line.match(re).captures

=\> ["Client", "MPEG-4", "390000", "700000", "24000"]

also,

> x,y,z=[1,2,3]

=\> [1, 2, 3]

> x

=\> 1

> z

=\> 3

> **···**
>
> From: Me Me [mailto:emanuelef@tiscali.it]

---

<div class="post-metadata">

**Author:** ![Chris7](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Chris7](https://rubytalk.org/u/Chris7)\
**Post date:** [18 September 2008 09:19 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/3 "2008-09-18T09:19:38Z")

</div>

> But I'm sure there's a better way, even considering that the number of  
> parameters can increase and I don't want to write a long regular  
> expression rule, that is hard to read.

Are the parameters always delimited by commas ? In which case you could  
modify the regular expression

&nbsp;&nbsp;line =~/(\w\*)=(.\*)/

Then

&nbsp;&nbsp;$2 #=\> "MPEG-4,390000,700000,24000"  
&nbsp;&nbsp;$2.split(",") #=\> ["MPEG-4", "390000", "700000", "24000"]

Returns you the values after the '=' sign in line as an array. For more  
power you could pass this sub-string to a CSV parsing library such as  
FasterCSV.

Chris

> **···**
>
> --  
> 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:** [18 September 2008 19:02 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/4 "2008-09-18T19:02:31Z")

</div>

s = "Client=MPEG-4,390000,700000,24000"  
&nbsp;&nbsp;&nbsp;&nbsp;==\>"Client=MPEG-4,390000,700000,24000"  
if s =~ /^\w+=\S+(,\d+)+$/  
&nbsp;&nbsp;vars = s.split( /[=,]/ )  
end  
&nbsp;&nbsp;&nbsp;&nbsp;==\>["Client", "MPEG-4", "390000", "700000", "24000"]

> **···**
>
> On Sep 18, 3:48 am, Me Me \<emanue...@tiscali.it\> wrote:
> 
> > Hi all,  
> > I would like to know if there's a better way to parse a string and  
> > assing values to variables;
> > 
> > Ex:
> > 
> > Client=MPEG-4,390000,700000,24000
> > 
> > I can do
> > 
> > line =~ /(\w\*)=([0-9A-Za-z -.:]\*),([0-9]\*),([0-9]\*),([0-9]\*)/
> > 
> > and
> > 
> > var1 = $1  
> > var2 = $2  
> > var3 = $3  
> > var4 = $4  
> > var4 = $5
> > 
> > But I'm sure there's a better way, even considering that the number of  
> > parameters can increase and I don't want to write a long regular  
> > expression rule, that is hard to read.

---

<div class="post-metadata">

**Author:** ![Ema\_Fuma](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Ema\_Fuma](https://rubytalk.org/u/Ema_Fuma)\
**Post date:** [18 September 2008 09:27 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/5 "2008-09-18T09:27:50Z")

</div>

Thans for answering,  
I was thinking if there some kind of c sscanf,  
so that I could parse and assing to variable at the same time

so if I have

line="Client=MPEG-4,390000,700000,24000"

something like:  
sscanf(line, %s=%s %s %d %d %d, val1, val2, val3, val4, val5, val6)

I don't know if there's a similar string function for this in Ruby

thanks

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

---

<div class="post-metadata">

**Author:** ![Lloyd\_Linklater](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Lloyd\_Linklater](https://rubytalk.org/u/Lloyd_Linklater)\
**Post date:** [19 September 2008 12:50 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/6 "2008-09-19T12:50:13Z")

</div>

William James wrote:

> s = "Client=MPEG-4,390000,700000,24000"  
> &nbsp;&nbsp;&nbsp;&nbsp;==\>"Client=MPEG-4,390000,700000,24000"  
> if s =~ /^\w+=\S+(,\d+)+$/  
> &nbsp;&nbsp;vars = s.split( /[=,]/ )  
> end  
> &nbsp;&nbsp;&nbsp;&nbsp;==\>["Client", "MPEG-4", "390000", "700000", "24000"]

You are right, William. That is cleaner. nice!

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

---

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [18 September 2008 09:44 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/7 "2008-09-18T09:44:02Z")

</div>

# I was thinking if there some kind of c sscanf,  
# so that I could parse and assing to variable at the same time  
# so if I have  
# line="Client=MPEG-4,390000,700000,24000"  
# something like:  
# sscanf(line, %s=%s %s %d %d %d, val1, val2, val3, val4, val5, val6)  
# I don't know if there's a similar string function for this in Ruby

you are right on scanf.  
there is one in ruby, and it's a lot simpler than you think

you'll have to require it though before using,

eg,

> require 'scanf'

=\> false

> line.scanf("%6s=%6s,%d,%d,%d,%d")

=\> ["Client", "MPEG-4", 390000, 700000, 24000]

> **···**
>
> From: Me Me [mailto:emanuelef@tiscali.it]

---

<div class="post-metadata">

**Author:** ![Ema\_Fuma](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Ema\_Fuma](https://rubytalk.org/u/Ema_Fuma)\
**Post date:** [18 September 2008 10:06 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/8 "2008-09-18T10:06:38Z")

</div>

> > line.scanf("%6s=%6s,%d,%d,%d,%d")
> 
> =\> ["Client", "MPEG-4", 390000, 700000, 24000]

Thanks  
the problem I have now is that the size of the string is not fixed to 6  
chars.  
And if I try to parse like:  
line.scanf("%s=%s,%d,%d,%d,%d")  
It doesn't parse the string.

Is there a way to parse any string?  
thanks again

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

---

<div class="post-metadata">

**Author:** ![Ema\_Fuma](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Ema\_Fuma](https://rubytalk.org/u/Ema_Fuma)\
**Post date:** [18 September 2008 12:46 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/9 "2008-09-18T12:46:13Z")

</div>

is there a way to use the scanf to parse a string not knowing how many  
chars?  
thanks

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

---

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [19 September 2008 01:13 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/10 "2008-09-19T01:13:09Z")

</div>

# \>\> line.scanf("%6s=%6s,%d,%d,%d,%d")  
# \> =\> ["Client", "MPEG-4", 390000, 700000, 24000]  
# the problem I have now is that the size of the string is not  
# fixed to 6 chars.  
# And if I try to parse like:  
# line.scanf("%s=%s,%d,%d,%d,%d")  
# It doesn't parse the string.  
# Is there a way to parse any string?  
# thanks again

oops, sorry, i thought it was good enough.

in that case, you'll have to use char classes,

> line.scanf("%[A-Za-z]=%[A-Z1-9-],%d,%d,%d,%d")

=\> ["Client", "MPEG-4", 390000, 700000, 24000]

is that ok?  
kind regards -botp

> **···**
>
> From: Me Me [mailto:emanuelef@tiscali.it]

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [18 September 2008 12:54 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/11 "2008-09-18T12:54:55Z")

</div>

> is there a way to use the scanf to parse a string not knowing how many  
> chars?

I'd still use Regexp.

line="Client=MPEG-4,390000,700000,24000"  
val1,val2,val3,val4,val5 =  
/^(\w\*)=([^,]\*),(\d\*),(\d\*),(\d\*)/.match(line).captures

Another way:

def handle\_line(v1,v2,v3,v4,v5)  
&nbsp;&nbsp;puts "I got it! #{v1} etc"  
end  
...  
if /^(\w\*)=([^,]\*),(\d\*),(\d\*),(\d\*)/ =~ line  
&nbsp;&nbsp;handle\_line(\*$~.captures)  
end

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

---

<div class="post-metadata">

**Author:** ![Ema\_Fuma](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Ema\_Fuma](https://rubytalk.org/u/Ema_Fuma)\
**Post date:** [18 September 2008 13:02 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/12 "2008-09-18T13:02:54Z")

</div>

Brian Candler wrote:

> > is there a way to use the scanf to parse a string not knowing how many  
> > chars?
> 
> I'd still use Regexp.
> 
> line="Client=MPEG-4,390000,700000,24000"  
> val1,val2,val3,val4,val5 =  
> /^(\w\*)=([^,]\*),(\d\*),(\d\*),(\d\*)/.match(line).captures
> 
> Another way:
> 
> def handle\_line(v1,v2,v3,v4,v5)  
> &nbsp;&nbsp;puts "I got it! #{v1} etc"  
> end  
> ...  
> if /^(\w\*)=([^,]\*),(\d\*),(\d\*),(\d\*)/ =~ line  
> &nbsp;&nbsp;handle\_line(\*$~.captures)  
> end

thanks,  
but what I would like to avoid regexp, it seems strange to me that  
there's no way to parse a string providing the structure.  
scanf would be great but if I put %s it doesn't get the string, unless I  
put the number of chars.

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

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [18 September 2008 13:09 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/13 "2008-09-18T13:09:18Z")

</div>

> thanks,  
> but what I would like to avoid regexp, it seems strange to me that  
> there's no way to parse a string providing the structure.  
> scanf would be great but if I put %s it doesn't get the string, unless I  
> put the number of chars.

%s is terminated by whitespace. You have no way of telling scanf that  
you want to treat "=" (after the first field) and "," (after the second  
field) as separators, rather than characters to be consumed by %s.

Well, as long as your data doesn't contain spaces, you could do

&nbsp;&nbsp;line="Client=MPEG-4,390000,700000,24000"  
&nbsp;&nbsp;line.gsub(/[=,]/,' ').scanf("%s %s %d %d %d")

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

---

<div class="post-metadata">

**Author:** ![Lloyd\_Linklater](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Lloyd\_Linklater](https://rubytalk.org/u/Lloyd_Linklater)\
**Post date:** [18 September 2008 13:13 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/14 "2008-09-18T13:13:05Z")

</div>

Me Me wrote:

> Brian Candler wrote:
> 
> > > is there a way to use the scanf to parse a string not knowing how many  
> > > chars?
> > 
> > I'd still use Regexp.
> 
> thanks,  
> but what I would like to avoid regexp, it seems strange to me that  
> there's no way to parse a string providing the structure.

Well, you can always write a BreakApart() algorithm but I must agree  
with Brian that RegEx is the way to go. After all, that is what RegEx  
does. I was tempted to add BreakApart() code here but I am neither sure  
that it is what you really want nor that it is the best solution for the  
problem at hand.

What is the \*actual\* problem? If it is what you said ("I would like to  
know if there's a better way to parse a string and assing values to  
variables;") then RegEx is a fine solution. If you reject a good  
solution and seek something else, then it can only be that you are  
actually seeking a solution to a different problem. So, what are you  
\*really\* looking for?

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

---

<div class="post-metadata">

**Author:** ![Ema\_Fuma](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Ema\_Fuma](https://rubytalk.org/u/Ema_Fuma)\
**Post date:** [18 September 2008 13:46 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/15 "2008-09-18T13:46:27Z")

</div>

> What is the \*actual\* problem? If it is what you said ("I would like to  
> know if there's a better way to parse a string and assing values to  
> variables;") then RegEx is a fine solution. If you reject a good  
> solution and seek something else, then it can only be that you are  
> actually seeking a solution to a different problem. So, what are you  
> \*really\* looking for?

I'm quite new to Ruby and I can understand that athere are better way to  
do things, what I would like to avoid is to write something like this  
(that works)

line =~ /(\w\*)=([0-9A-Za-z -.:]\*),([0-9A-Za-z -.:]\*),([0-9A-Za-z  
-.:]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*)/

I wanted to this in one line but in a more mainable way, otherwise I  
could always pars the string char by char.

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

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [18 September 2008 14:04 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/16 "2008-09-18T14:04:37Z")

</div>

> > What is the \*actual\* problem? If it is what you said ("I would like to  
> > know if there's a better way to parse a string and assing values to  
> > variables;") then RegEx is a fine solution. If you reject a good  
> > solution and seek something else, then it can only be that you are  
> > actually seeking a solution to a different problem. So, what are you  
> > \*really\* looking for?
> 
> I'm quite new to Ruby and I can understand that athere are better way to  
> do things, what I would like to avoid is to write something like this  
> (that works)
> 
> line =~ /(\w\*)=([0-9A-Za-z -.:]\*),([0-9A-Za-z -.:]\*),([0-9A-Za-z  
> -.:]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*)/

I believe there's a bug in your regex. I assume you don't really mean all characters between space and period in the second character class, especially since that includes a comman.

> I wanted to this in one line but in a more mainable way, otherwise I  
> could always pars the string char by char.

I would probably do it in two steps. Match the bit before and after the equal sign in one, then split() the after bit on commas:

#!/usr/bin/env ruby -wKU

if "Client=MPEG-4,390000,700000,24000" =~ /\A([^=]+)=([^=]+)\z/  
&nbsp;&nbsp;&nbsp;p [$1, \*$2.split(",")]  
end

\_\_END\_\_

Here's another idea using StringScanner:

#!/usr/bin/env ruby -wKU

require "strscan"

class SimpleParser  
&nbsp;&nbsp;&nbsp;def initialize(data)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s = StringScanner.new(data)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@values =

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@values \<\< s.matched if s.scan(/\w+/)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@values \<\< s.matched[1..-1] if s.scan(/=[0-9A-Za-z \-.:]+/)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@values \<\< s.matched[1..-1] while s.scan(/,[0-9]+/)  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;attr\_reader :values  
end

p SimpleParser.new("Client=MPEG-4,390000,700000,24000").values

\_\_END\_\_

Hope that gives you some fresh ideas.

James Edward Gray II

> **···**
>
> On Sep 18, 2008, at 8:46 AM, Me Me wrote:

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [18 September 2008 14:11 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/17 "2008-09-18T14:11:50Z")

</div>

> what I would like to avoid is to write something like this  
> (that works)
> 
> line =~ /(\w\*)=([0-9A-Za-z -.:]\*),([0-9A-Za-z -.:]\*),([0-9A-Za-z  
> -.:]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*)/
> 
> I wanted to this in one line but in a more mainable way, otherwise I  
> could always pars the string char by char.

If you don't actually need to match the data against a pattern, then  
just use

&nbsp;&nbsp;line.split(',')

If you only want to proceed if the line is "valid", then write a  
suitable regexp pattern to validate it. There are plenty of shortcuts.  
For example, \d is the same as [0-9]. {n} means repeat the preceeding  
element exactly n times. So:

&nbsp;&nbsp;case line  
&nbsp;&nbsp;when /^(\w\*)=([^,]\*),(\d+(,\d+){9})$/  
&nbsp;&nbsp;&nbsp;&nbsp;key1 = $1  
&nbsp;&nbsp;&nbsp;&nbsp;key2 = $2  
&nbsp;&nbsp;&nbsp;&nbsp;numbers = $3.split(/,/).collect { |n| n.to\_i }  
&nbsp;&nbsp;&nbsp;&nbsp;# or: numbers = $3.scanf("%d %d %d %d %d %d %d %d %d %d") if you  
prefer  
&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;puts "Invalid line!"  
&nbsp;&nbsp;end

That matches word=string,n,n,n,n,n,n,n,n,n,n

Furthermore you can substitute patterns you use repeatedly:

&nbsp;&nbsp;WORD = "[0-9A-Za-z -.:]\*"  
&nbsp;&nbsp;...  
&nbsp;&nbsp;when /^(#{WORD})=(#{WORD}),(#{WORD}),(\d+(,\d+){9})$/o

(//o means that the regexp is built only once, the substitutions aren't  
done every time round)

You can also use extended syntax to make the RE more maintainable:

&nbsp;&nbsp;VALID\_LINE = %r{ ^  
&nbsp;&nbsp;&nbsp;&nbsp;(\w\*) = # key ($1)  
&nbsp;&nbsp;&nbsp;&nbsp;(#{WORD}), # format ($2)  
&nbsp;&nbsp;&nbsp;&nbsp;(\d+), # size ($3)  
&nbsp;&nbsp;&nbsp;&nbsp;(\d+) # sample rate ($4)  
&nbsp;&nbsp;$ }x

&nbsp;&nbsp;if VALID\_LINE =~ line  
&nbsp;&nbsp;&nbsp;&nbsp;..  
&nbsp;&nbsp;end

You can also do groupings which \*don't\* capture data using (?: .. )

Compact enough?

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

---

<div class="post-metadata">

**Author:** ![Lloyd\_Linklater](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Lloyd\_Linklater](https://rubytalk.org/u/Lloyd_Linklater)\
**Post date:** [18 September 2008 18:15 UTC](https://rubytalk.org/t/suggestion-for-string-parsing/49150/18 "2008-09-18T18:15:30Z")

</div>

Me Me wrote:

> > What is the \*actual\* problem? If it is what you said ("I would like to  
> > know if there's a better way to parse a string and assing values to  
> > variables;") then RegEx is a fine solution. If you reject a good  
> > solution and seek something else, then it can only be that you are  
> > actually seeking a solution to a different problem. So, what are you  
> > \*really\* looking for?
> 
> I'm quite new to Ruby and I can understand that athere are better way to  
> do things, what I would like to avoid is to write something like this  
> (that works)
> 
> line =~ /(\w\*)=([0-9A-Za-z -.:]\*),([0-9A-Za-z -.:]\*),([0-9A-Za-z  
> -.:]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*),([0-9]\*)/
> 
> I wanted to this in one line but in a more mainable way, otherwise I  
> could always pars the string char by char.

AHA! I understand, or I at least flatter myself that I do. how about  
this:

require 'scanf'

s = "Client=MPEG-4,390000,700000,24000,9452349,234583475,2452345"  
val = s.scanf("%6s=%s")  
vals = val[1].split(",")  
p vals

=\> ["MPEG-4", "390000", "700000", "24000", "9452349", "234583475",  
"2452345"]

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