Added check for global flag in pattern.
Merge pull request #397 from arb/pattern-fix

Added check for global flag in pattern.