command line – Terminal: why -iregex option with find instead of -regex with case insensitive flag (?i)

According to the man pages we should be able to use regex with the native find command like so:

find -E /Volumes/complete -regex "(?i).*frontline.*"

However it fails. I have tried quite a few variations which have also failed.

find -E /Volumes/complete -regex ".*frontline.*i"

find -E /Volumes/SeedDrive/complete -regex "(?i:.*frontline.*)" find: -regex: (?i:.*frontline.*): repetition-operator operand invalid

find -E /Volumes/SeedDrive/complete -regex "(?i:.*frontline.*)"

find /Volumes/SeedDrive/complete -regex "*[fF]rontline.*"

Don't understand why but single quotes does work:

find -E /Volumes/SeedDrive/complete -regex '.*[fF]rontline.*'

finds “frontline” or “Frontline”

Problem is I also have files that contain FRONTLINE, Frontline, frontline.

man find says:

The options are as follows:

 -E      Interpret regular expressions followed by -regex and -iregex
         primaries as extended (modern) regular expressions rather than
         basic regular expressions (BRE's).  The re_format(7) manual page
         fully describes both formats.

man re-format says”

Inline Options (available for enhanced extended REs only)
Like the inline literal mode mentioned above, other options can be switched
on and off for part of a RE. ‘(?o..)’ will turn on the options specified
in o.. (one or more options characters; see below), while ‘(?-o..)’ will
turn off the specified options, and ‘(?o1..-o2..)’ will turn on the first
set of options, and turn off the second set.

 The available options are:

       i      Turning on this option will ignore case during matching, while
              turning off will restore case-sensitive matching.  If
              REG_ICASE was specified to regcomp(), this option can be use
              to turn that off.

The scope of the option change begins immediately following the right
parenthesis, but up to the end of the enclosing subexpression (if any).
Thus, for example, given the RE ‘(fu(?i)bar)baz’, the ‘fu’ portion matches
case sensitively, ‘bar’ matches case insensitively, and ‘baz’ matches case
sensitively again (since is it outside the scope of the subexpression in
which the inline option was specified).

 The inline options syntax can be combined with the non-capturing
 parenthesized subexpression to limit the option scope to just that of the
 subexpression.  Then, for example, ‘fu(?i:bar)baz’ is similar to the
 previous example, except for the parenthesize subexpression around
 ‘fu(?i)bar’ in the previous example.

Author: Subham

Leave a Reply

Your email address will not be published. Required fields are marked *