0

When using powergrep, there is an option called: file sectioning and the first 3 options are:

  • do not section files.
  • line by line
  • line by line including line breaks

I am guessing that first option would be similar to Perl's 'm' modifier ("^" matches the start of the string and after each newline; "$" matches before each newline and at the end of the string), and the option Dot matches new lines, would be as if Perl's 's' modifier was used ("." matches all characters rather than excluding newlines).

I don't understand the two following options. Line by line and still you can turn on the check box dot matches new lines. And line by line including line breaks would be (?s) modifier again, so I don't understand those options.

Please can somebody explain those options? and the relation with s and m modifiers.

ikegami
  • 367,544
  • 15
  • 269
  • 518
alex
  • 95
  • 6

2 Answers2

1

To turn on dot matches newline for one regex, put (?s) in front of it.

(?n) or -line enables what Tcl calls "newline-sensitive matching". The dot and negated character classes will not match newlines. The caret and dollar will match after and before newlines. Specifying (?n) or -line is the same as specifying (?pw) or -linestop -lineanchor.

(?m) is a historical synonym for (?n).

http://www.regular-expressions.info/tcl.html

Community
  • 1
  • 1
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
1

I don't know powergrep, but it sounds like those they control against what you are matching.

  • "Do not section files" matches against the entire file.

    my $file = do { local $/; <$fh> };
    $file =~ /.../;
    
  • "Line by line including line breaks" matches against each line.

    while (my $line = <$fh>) {
       $line =~ /.../;
    }
    
  • "Line by line" matches against each line, chomped.

    while (<$fh>) {
       chomp( my $chomped_line = $_ );
       $chomped_line =~ /.../;
    }
    

There's no doubt that "Dot matches new lines" is equivalent to the s modifier.

ikegami
  • 367,544
  • 15
  • 269
  • 518