Regex to detect a blank line


I want to use reader.readThrough() to read a file until a blank line is encountered. I use a regex to detect a blank line. Code:

use IO, Regex;
config const infilename = ("INFO.OUT");

var blankLine = new regex("^\s*$");
var success : bool;
var chunk : string;
var f = open(infilename, ioMode.r);
var infile = f.reader();
success = infile.readThrough(blankLine,chunk,-1,true);

writeln("Read ", chunk.size, " items.");

Running the code outputs:
Read 1 items.

The '+' is the first character in the file. The regex is intended to represent a blank line or one that contains only whitespace. I expect the chunk to be:

| Elk version 7.1.14 started |

Clearly the regex does not do what I intended, or I have misunderstood what readThrough() is intended to do . I've looked through the regex documentation without enlightenment. I appreciate any help offered.


Hello again,

Discovered that "\n\s*\n" does what I want. Sorry for the noise.


1 Like