From: Josh Law <objecting@objecting.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Josh Law <objecting@objecting.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 3/7] lib/glob: accept [^...] as character class negation syntax
Date: Sun, 15 Mar 2026 17:11:00 +0000 [thread overview]
Message-ID: <20260315171104.268944-4-objecting@objecting.org> (raw)
In-Reply-To: <20260315171104.268944-1-objecting@objecting.org>
glob(7) specifies [!...] for negated character classes, but many
users are more familiar with the regex-style [^...] syntax. Tools
like git, rsync, and bash all accept both forms, and the difference
is a common source of confusion when writing glob patterns.
Accept '^' as an alias for '!' at the start of a character class so
that both [!a-z] and [^a-z] work as expected.
Signed-off-by: Josh Law <objecting@objecting.org>
---
lib/glob.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/glob.c b/lib/glob.c
index df7f00619b1b..c5508be0d215 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -33,9 +33,9 @@ MODULE_LICENSE("Dual MIT/GPL");
* Like !fnmatch(@pat, @str, 0) and unlike the shell, this does NOT
* treat / or leading . specially; it isn't actually used for pathnames.
*
- * Note that according to glob(7) (and unlike bash), character classes
- * are complemented by a leading !; this does not support the regex-style
- * [^a-z] syntax.
+ * Note that according to glob(7), character classes are complemented by
+ * a leading !. The regex-style [^a-z] syntax is also accepted as an
+ * alias.
*
* An opening bracket without a matching close is matched literally.
*/
@@ -72,7 +72,7 @@ bool __pure glob_match(char const *pat, char const *str)
case '[': { /* Character class */
if (c == '\0') /* No possible match */
return false;
- bool match = false, inverted = (*pat == '!');
+ bool match = false, inverted = (*pat == '!' || *pat == '^');
char const *class = inverted ? pat + 1 : pat;
unsigned char a = *class++;
--
2.34.1
next prev parent reply other threads:[~2026-03-15 17:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 17:10 [PATCH 0/7] lib/glob: fixes, new features, and test coverage Josh Law
2026-03-15 17:10 ` [PATCH 1/7] lib/glob: normalize inverted character class ranges Josh Law
2026-03-15 17:10 ` [PATCH 2/7] lib/glob: treat trailing backslash as literal character Josh Law
2026-03-15 17:11 ` Josh Law [this message]
2026-03-15 17:11 ` [PATCH 4/7] lib/glob: add case-insensitive glob_match_nocase() Josh Law
2026-03-15 17:11 ` [PATCH 5/7] lib/glob: add glob_validate() for pattern syntax checking Josh Law
2026-03-15 17:11 ` [PATCH 6/7] lib/tests: add glob test cases for escapes, edge cases, and new features Josh Law
2026-03-15 17:11 ` [PATCH 7/7] lib/tests: add kunit tests for glob_match_nocase() and glob_validate() Josh Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260315171104.268944-4-objecting@objecting.org \
--to=objecting@objecting.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.