From: Jo R. <jr...@sv...> - 2006-03-13 20:32:33
|
On Fri, Mar 10, 2006 at 02:37:36PM +0100, Roland Giersig wrote: > Expect collects all output into a buffer (the accumulator) and matches > against that. This is the mindset you should program in: you have a > string with multiple lines in it. > > So here are a few rules: > > To match a line, use "^.*\n". Note that "." will not match a newline > until you use single-line matching (the option or "(?s)"). My syntax reading fouled up, and I'm confused. "the option" is what? And what did you mean by "(?s)" My first read was using ? for smallest match (ie "(.*?)\n"), but now I'm not so sure. > Note that "\s" WILL match a newline, so it gives unexpected results with > empty lines (as you have already found out). Use "[ \t]" instead. > > To match against the end of buffer (which IMHO is a bad idea), use "\z". > > Don't use "$" or "\Z", instead always anchor your patterns at the start > of the line. Anchoring at the start of the line is fine, but how to properly detect the end of the line is the question. Lines where I know the start but don't know the end (and thus need to find and output the lines) is the issue. /^[ \t]+Line starts with(.*?)[\r\n]+/ ..doesn't seem to work /^[ \t]+Line starts with(.*?)$/ .. does work, but can also match a partial line in the accumulator. /^[ \t]+Line starts with(.*?)\r+$/ .. does work In short, I'm not convinced that \n is actually matching right now. And this all makes sense, but goes explicitly against the documentation that says that line-matching can be done with ^ and $. It seems likely that the documentation is out of date, but... -- Jo Rhett senior geek SVcolo : Silicon Valley Colocation |