Add support for regex flags in pattern validation

Based on the PR #550 made by  @nathancharles and the recomendation you gave there I submit this PR to  add support for flags in pattern matching. 
Let me know if there's anything wrong or that needs improvement!