3.2. Modifiers: Case Sensitivity and Global Matching

Regular expressions are case-sensitive by default. To ignore case, use the modifier i (for "ignore"). Thus, /pounds?/ finds pound and pounds, and /pounds?/i finds Pound and Pounds as well. This modifier can be combined with the global modifier: use /pounds?/gi to find words globally and case-insensitively. The other available modifier in JavaScript, g, was illustrated earlier: /pounds?/g matches every instance of pound and pounds, in a text, /pounds?/ finds just the first occurrence. The two modifiers can be combined to match globally and case-insensitively: /pounds?/gi (the order of these modifiers doesn't matter).

Get Automating InDesign with Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.