# IO#gets with regex

**URL:** <https://www.ruby-forum.com/t/io-gets-with-regex/143083>\
**Category:** Ruby\
**Created:** [July 15, 2008, 1:46am UTC](https://www.ruby-forum.com/t/io-gets-with-regex/143083 "2008-07-15T01:46:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![morris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@morris](https://www.ruby-forum.com/u/morris)\
**Post date:** [July 15, 2008, 1:46am UTC](https://www.ruby-forum.com/t/io-gets-with-regex/143083/1 "2008-07-15T01:46:51Z")

</div>

hi,

in ruby 1.8.7, IO#gets takes a seperator string as argument. i suggest  
adding support for a regular expression to match any seperator. this  
way, one could check for different seperators like \n\t\0 etc. this is  
mainly useful for File IO.

example:  
handle = File.open “test.in”  
$/ = / \n\t/  
str = handle.gets

if there’s any other efficient way (other than using IO#getc and read  
the file char by char) to achieve the same thing, i’d be happy to know  
about it.

– morris

---

<div class="post-metadata">

**Author:** ![morris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@morris](https://www.ruby-forum.com/u/morris)\
**Post date:** [July 16, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/io-gets-with-regex/143083/2 "2008-07-16T13:23:52Z")

</div>

Morris Brodersen wrote:

> in ruby 1.8.7, IO#gets takes a seperator string as argument. i suggest  
> adding support for a regular expression to match any seperator.

That’d be problematic as its not always possible to accurately apply a  
regex  
to a file (or whatever the IO comes from) without reading the whole file  
(not  
without restrictions on the regex anyway), which would kind of defeat  
the  
purpose of using gets instead of read.
