<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -194,19 +194,24 @@ class FileString
   alias size length
   alias bytesize length
 
-  def [](off, len=nil)
+  def [](*args)
     file_size = length
-    off, len  = *_normalize_index(file_size, off, len)
 
-    if off &gt; file_size then
-      nil
-    elsif off == file_size then
-      &quot;&quot;
+    if Regexp === off then
+      _read[*args]
     else
-      _open { |fh|
-        fh.seek(off)
-        fh.read(len)
-      }
+      off, len = *_normalize_index(file_size, *args)
+
+      if off &gt; file_size then
+        nil
+      elsif off == file_size then
+        &quot;&quot;
+      else
+        _open { |fh|
+          fh.seek(off)
+          fh.read(len)
+        }
+      end
     end
   end
 
@@ -217,24 +222,31 @@ class FileString
 
     file_size = length
     data      = args.pop
-    off, len  = _normalize_index(file_size, *args)
-
-    if off &gt; file_size then
-      raise IndexError, &quot;index #{off} out of file&quot;
-    elsif data.length == len then
-      _open(&quot;r+b&quot;) { |fh|
-        fh.seek(off)
-        fh.write(data)
-      }
+
+    if Regexp === args.first then
+      content = _read
+      content[*args] = data
+      _write(content)
     else
-      _open(&quot;r+b&quot;) { |fh|
-        fh.seek(off+len)
-        rest = fh.read
-        fh.seek(off)
-        fh.write(data)
-        fh.write(rest)
-        fh.truncate(file_size-len+data.length) if data.length &lt; len
-      }
+      off, len  = _normalize_index(file_size, *args)
+
+      if off &gt; file_size then
+        raise IndexError, &quot;index #{off} out of file&quot;
+      elsif data.length == len then
+        _open(&quot;r+b&quot;) { |fh|
+          fh.seek(off)
+          fh.write(data)
+        }
+      else
+        _open(&quot;r+b&quot;) { |fh|
+          fh.seek(off+len)
+          rest = fh.read
+          fh.seek(off)
+          fh.write(data)
+          fh.write(rest)
+          fh.truncate(file_size-len+data.length) if data.length &lt; len
+        }
+      end
     end
 
     self
@@ -326,9 +338,9 @@ class FileString
             found  = buffer.index(obj)
             offset = fh.pos - 2*read_size
           end while found.nil? &amp;&amp; append = fh.read(read_size)
-        end        
+        end
       end
-          
+
       found ? found + offset : found
     }
   end
@@ -446,7 +458,7 @@ class FileString
       def #{method_name}(*args, &amp;block)
         _read.#{method_name}(*args)
       end
-    
+
       def #{method_name}!(*args, &amp;block)
         data = _read
         rv   = data.#{method_name}!(*args, &amp;block)
@@ -488,7 +500,7 @@ class FileString
       end
     END_OF_METHODS
   end
-  
+
   # Methods called directly on the read-open filehandle
   %w[
     bytes
@@ -517,7 +529,7 @@ class FileString
   alias intern to_sym
 
   def to_s
-    File.read(@path)
+    _read
   end
   alias to_str to_s
 </diff>
      <filename>lib/filestring.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fb9486c71be4277708e08e8ebb2c4c5be246db88</id>
    </parent>
  </parents>
  <author>
    <name>Stefan Rusterholz</name>
    <email>stefan.rusterholz@gmail.com</email>
  </author>
  <url>http://github.com/apeiros/filestring/commit/781c728d5ec41f9c8be851c4830b19d4c02b7bc7</url>
  <id>781c728d5ec41f9c8be851c4830b19d4c02b7bc7</id>
  <committed-date>2009-11-09T19:32:11-08:00</committed-date>
  <authored-date>2009-11-09T19:32:11-08:00</authored-date>
  <message>Added regex capability to [] and []= - thanks to Robert Klemme.</message>
  <tree>b325ae6860aa97336c0fd36f24ecc7e9064a376c</tree>
  <committer>
    <name>Stefan Rusterholz</name>
    <email>stefan.rusterholz@gmail.com</email>
  </committer>
</commit>
