Nuby - help on string spliting

D

Dany Cayouette

Any advice/ideas on the best way of attacking field split on ';' when the string looks like:

s = 'a;b;c\;;d;'

i.e. field delimiter is ';', and if ; appears in field data ; => \;

Any regex magic? or should I use s.each_byte and do it by hand?

Thanks,
Dany
 
S

Simon Strandgaard

Any advice/ideas on the best way of attacking field split on ';' when the
string looks like:

s = 'a;b;c\;;d;'

i.e. field delimiter is ';', and if ; appears in field data ; => \;

Any regex magic? or should I use s.each_byte and do it by hand?


hmmm.. your mail looks exactly like a mail I have replied to 2 minutes ago.
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/114414


something like this

irb(main):023:0> "aa;bbb\\;;abc;;d\\\\;e;f".scan(/(?:\A|;)((?:\\[^.]|[^;])*)/)
{ p $1 }
"aa"
"bbb\\;"
"abc"
""
"d\\\\"
"e"
"f"
=> "aa;bbb\\;;abc;;d\\\\;e;f"
irb(main):024:0>


btw: are you solving some kind of exercise ?
 
D

Dany Cayouette

btw: are you solving some kind of exercise ?

No. Mark introduced me to ruby. He's a programmer;I'm not! so I usually bounce questions off him. Got confused as I thought he was telling me to post to comp.lang.ruby, while he was actually posting himself. Sorry for the duplication...

Dany
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top