From: 7stud -- Date: 2008-01-31T05:50:13+09:00 Subject: Re: Parsing a string with quotes Cheri Ruska wrote: > Thank you for your help. Where is a good resource to read up on what > this code means? %r/["'][^"']+["']|\w+/ > The topic is called 'regular expressions'. That regular expression says to find a matching substring where: 1) The first character is either a single or double quote: ['"] Brackets allow you to specify a group of characters, e.g. [a-z]. If the first character in a matching substring is any of the characters in the specified group, then there is a match. 2) Followed by a character that is not(^) one of the characters in the specified group: [^'"] If the first character between brackets is ^, it means look for any character not specified between the brackets. 3) The + after the brackets says to look for "one or more" of the preceding matching character, i.e. not a single or double quote. 4) Followed by a single or double quote: ["'] 5) The pipe(|) means OR. So a substring will also match if the symbols following the pipe match. 6) \w means any 'word character', which is short hand for: [a-zA-Z0-9] Once again the + sign following the \w means to match the \w one or more times. The result is that the regex matches any phrase surrounded by single or double quotes OR any series of characters [a-zA-z0-9]. Note that a space will not match \w so when a space is encountered, the match ends. -- Posted via http://www.ruby-forum.com/.