From: Jeff Pritchard Date: 2006-06-01T12:15:12+09:00 Subject: Re: Parsing a string using multiple regexs Hi Jason, I'm a newbie too, but thought I might be able to help on this one. Unfortunately, I think we need a little bit more information about what to expect in the string. Is it always specifically of the form: something in quotes followed by something between commas followed by two space separated other things? Or might the order be different, or some part of it is missing, etc. Since each part has a different type of separation, it almost seems as if you will need to look for each part separately. maybe start out with: tags =~ /"(.*)"/ # first tag is anything inside quotes a[0] = $1 # parenthesis form a group, which is stored in $1 variable tags =~ /[,]\s*([^,])\s*[,]/ # second tag is anything between commas a[1] = $1 temp = tags =~ /.*([^,])/ # get everything after the last comma (would this work?) a[2],a[3] = temp.split(' ') # split whatever is left at the space and put in tags 3 and 4 Being a newbie myself, I can almost guarantee three things about this reply: 1) three or four other people probably beat me to it while I was figuring it out 2) there's bound to be at least four errors in my answer - but at least I gave it a shot 3) there's probably a much more eloquent solution (or four of them since it's ruby) best of luck learning this bizarre but fascinating language, jp web mail wrote: > > To whomever can help, > > I need to parse a string into parts using multiple regexs, and I'm new > to Ruby, so I have NO idea how to do it. Basically, I'm trying to parse > tags that users might add on a webpage. > > Example: In my tags input box, user enters the following: > "my first tag", second tag, third_tag fourth_tag > > The order of precedence is quotes, then commas then spaces, so my > results should be a ruby array which contains the values: > > my first tag > second tag > third_tag > fourth_tag > > which means the array will have 4 elements. > > I desperately need help. Anyone ? > > Thanks, > > Jason -- Posted via http://www.ruby-forum.com/.