"Paul" <paul.rogers / shaw.ca> schrieb im Newsbeitrag news:4ee21163.0405281638.45d95197 / posting.google.com... > How do I extract the name and value from the following lines: > > name=paul value=10 otherstuff=123 > > but the line may also be: > name='hello paul' value='10' otherstuff='123' > > I know it has to do with \0 \1 etc, but cant figure out how to make > the re work for both cases > > Thanks You could do: lines = <<'EOF' name=paul value=10 otherstuff=123 name='hello paul' value='10' otherstuff='123' name='hello paul, it\'s nice here' value='10' otherstuff='123' name='hello paul, don't do that' value='10' otherstuff='123' EOF lines.scan( %r{ (name|value|otherstuff) = (?: '((?:[^'\\]|\\')*)' | (\S+) ) }x ) do |m| key = m[0] val = (m[1]||m[2]).gsub(/\\(.)/, '\\1') puts "key=#{key}" puts "value='#{val}'" end $ ./sc.rb key=name value='paul' key=value value='10' key=otherstuff value='123' key=name value='hello paul' key=value value='10' key=otherstuff value='123' key=name value='hello paul, it's nice here' key=value value='10' key=otherstuff value='123' key=name value='hello paul, don' key=value value='10' key=otherstuff value='123' Of course you can replicate the expression to cover all three x=y pairs. Regards robert