From: Dave Bass Date: 2008-06-08T01:04:05+09:00 Subject: Re: Remove Parts of a String Victor Reyes wrote: > to understand: > > str.gsub(/:[^,]*(?:$|(?=,))/,'').split( ',') > > you need a PhD in "General Expresionology". Ruby is supposed to be > simple. At a glance you can see that gsub does something to str, and then split does something to the result. So the top level's quite straightforward. The gsub regexp is not easy to understand however, and this is one of the problems with regexps in general. They're concise but obscure. Generally speaking one builds them up a little at a time, using quite a bit of trial and error -- or at least, that's how I do it, maybe other people get there in one! A regexp like this deserves several lines of comments to explain what's going on. For some reason coders hate writing comments. I would tend to do a job like this in several stages rather than in one line. I've learnt by bitter experience that my future self finds it difficult to understand concise code that my past self has written! -- Posted via http://www.ruby-forum.com/.