On Sat, Jun 6, 2026 at 4:40 PM Philip Prindeville via Bug reports for GNU
grep <[email protected]> wrote:

> Trying to figure out how to best integrate this functionality.
>
> It occurred to me that glob(3) is built-in to libc, but the
> Xcompile()/Xexecute() model seems to be biases to regex-like approaches, if
> I've read the code correctly.
>
> I could translate patterns into regex's:
>
> 1. Prepend ^
>
> 2. Translate:
>
>   . => \.
>   ? => [^/]
>   * => [^/]*
>   \x => \x
>   {a,b} => (a|b)
>   [xyz] => [xyz]
>   x => x
>
>   There's a little more subtlety than that... for instance, how [xyz] gets
> collected if x is ']' then x is rewritten as \].  And x, y, and z can't be
> /.
>
> 3. Append $
>
> Is there a better way?


Thanks for the suggestion, but...

Any glob-to-regex code should address the "**" question. And the file name
separator: "/" vs "\".
Since it's pretty easy to create (or find) a tiny script to convert a glob
to a regular expression, anyone who wants to grep-via-glob can wrap their
glob in an invocation of the converter.

Thus, I cannot justify encumbering grep with this.

Reply via email to