Jeff, Ezra,

Thanks tons for the help. You guys both helped a lot. My only question 
so far, for Ezra, is this: My second tag is "second tag", not in quotes, 
but with a space between the two words. The tag IS meant to be two words 
long. So I'm thinking that if you replace all the commas with spaces, 
wont that split my second tag into two tags, when it was meant to be 
just one tag ?

Jeff,

The tags can appear in any order, and they can either be quoted, 
separated by commas, or separated by spaces. I've decided that in the 
case of all three, i would like quotes to have precedence, followed by 
commas, followed by spaces. so, for an example, the following string:

"hello, i love you", was written by, the doors

i think would have the expected behaviour of creating the following tags

tag1 = "hello, i love you"
tag2 = was written by
tag3 = the doors

whereas the line

"hello, i love you" was written by the doors

would be

tag1 = "hello, i love you"
tag2 = was
tag3 = written
tag4 = by
tag5 = the
tag6 = doors

this is just the way i thought i should handle the users input. if 
anyone has better suggestions, i'm open to them. the problem being 
solved is how to take user input typed in a textbox and split it into 
tags, while handling things like quotes, commas, whatever.

thanks again

- jason

Jeff Pritchard wrote:
> Thanks Ezra,
> I was sure I would learn something by attempting an answer.  I learned 
> several somethings:
> 
> tags << next answer
> (cleaner than using subscripts)
> 
> input.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
> (remove the stuff you find as you find it - brilliant!)
> 
> /\"(.*?)\"\s*/
> (don't forget to escape the quotes and use ? to make .* less greedy)
> 
> # replace all commas with a space
> (if you can't get there from here, go someplace else first!)
> 
> tags.concat input.split(/\s/)
> (another cool way to shove some more answers into the answer array)
> 
> # strip whitespace from the names
>>      tags.map! { |t| t.strip }
> (instead of making the regexp more complicated, do it simply and then
> clean up the results)
> 
> # delete any blank tag names
>>      tags = tags.delete_if { |t| t.empty? }
> (yet another iterator I never heard of before)
> 
> 
>  def parse_tags(input)
>  ...
> end
> (modularize everything as you go!)
> 
> 
> P.S. Ezra, thanks for recommending RimuHosting, they've been great!
> 
> best,
> jp
> 
> 
> Ezra Zygmuntowicz wrote:
>> On May 31, 2006, at 4:06 PM, web mail wrote:
>> 
>>>
>>> I desperately need help. Anyone ?
>>>
>>> Thanks,
>>>
>>> Jason
>>>
>>> -- 
>>> Posted via http://www.ruby-forum.com/.
>>>
>> 
>> 
>>    def parse_tags(input)
>>      tags = []
>>      # pull out the quoted tags
>>      input.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
>>      # replace all commas with a space
>>      input.gsub!(/,/, " ")
>>      # get whatever's left
>>      tags.concat input.split(/\s/)
>>      # strip whitespace from the names
>>      tags.map! { |t| t.strip }
>>      # delete any blank tag names
>>      tags = tags.delete_if { |t| t.empty? }
>>      return tags
>>    end
>> 
>> 
>> -Ezra


-- 
Posted via http://www.ruby-forum.com/.