in reply to RegEx Beginning of line or whitespace match

try with this :

if ($line =~ /(\s+|^)(for\()/gi) { print 'match'; }

Replies are listed 'Best First'.
Re^2: RegEx Beginning of line or whitespace match
by ZlR (Chaplain) on Feb 12, 2005 at 17:22 UTC
  • I do not think the alternation of space with "start of line" is a good thing .
    It's not good style and it looks like it can cause problems.
    Use ^\s* instead .

  • You don't need to remember the patterns so why use () to match the spaces ?

  • What would the /g modifier do in such a context ? I don't like it with a start of line.

    Regards,
    ZlR.