5

This is example found in perldoc:

  $object->expect(15, '-re', "$str");

I want to add option 'i' to the match. This won't work:

$object->expect(15, '-re', qr/$str/i);

Do I have to use this format:

 $exp->expect($timeout, [ qr/$str/i, sub {}], $shell_prompt);
toolic
  • 57,801
  • 17
  • 75
  • 117
Jay Zhou
  • 51
  • 1

1 Answers1

3

You can embed directives into the regex itself:

$object->expect(15, '-re', "(?i)$str");

ref: http://perldoc.perl.org/perlre.html#Extended-Patterns

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • 1
    `qr/foo/i` is actually `(?i:foo)`. `(?i)foo` generally equivalent, but it relies on Expect embedding the pattern in `(?:...)` to limit the scope of the case-insensitivity. – ikegami Oct 14 '15 at 15:35
  • It will rely on $str not containing an unmatched close parenthesis. I suppose we'll have to assume it's a well-formed regex in the first place, or rely on the rest of the code to catch the error. – glenn jackman Oct 14 '15 at 16:44