<p>By &quot;wildcard matching&quot; I mean the following:</p>
<ul>
<li><code>*</code> matches zero or more of any characters. E.g. <code>B*</code> matches any string starting with <code>B</code>, including just <code>B</code>.</li>
<li><code>?</code> matches any one character. E.g. <code>???</code> matches any string that is exactly three characters long.</li>
<li><code>[abc]</code> matches any of the enclosed characters (with a few exceptions noted below). E.g. <code>[HCB]at</code> matches <code>Hat</code>, <code>Cat</code>, or <code>Bat</code>.</li>
<li><code>[x-y]</code> matches any character in the specified range. E.g. <code>[0-9]</code> matches any digit.</li>
<li><code>[^...]</code> negates the character class. E.g. <code>[^0-9]</code> matches any non-digit character.</li>
</ul>
<p>The above is the syntax commonly used in tools like <code>glob</code> (which also usually have a few path-specific features not mentioned above). SQL also supports similar, but using <code>%</code> instead of <code>*</code>, and <code>_</code> instead of <code>?</code>.</p>
<p>I don't care about path-specific variants or extensions such as path separators, <code>**</code>, or ignored leading <code>.</code>, this is focused on string matching specifically.</p>
<p>Some variants I found already:</p>
<ul>
<li><a href="https://learn.microsoft.com/en-us/office/vba/access/concepts/structured-query-language/like-operator-microsoft-access-sql" rel="nofollow noreferrer">At least one database</a> supports <code>#</code> as a synonym for <code>[0-9]</code>.</li>
<li>Bash supports an <a href="https://www.linuxjournal.com/content/bash-extended-globbing" rel="nofollow noreferrer">extended version of globbing</a>, using syntax like <code>?(...)</code> (one or zero of the enclosed patterns), <code>*(...)</code> (zero or more of the enclosed patterns), etc. (Bash also supports more complex extensions such as alternation, which is closer to regex and hence a little beyond the scope of this question.)</li>
<li>Many glob and SQL implementations support <code>[!...]</code> for negation of a character class instead of/in addition to <code>[^...]</code>.</li>
</ul>
<p>So, my question is, are there any other syntax options for this? And are there any other extensions I'm not aware of here? I'm not looking for something as complex as a regex here (e.g. alternation, backtracking or similar is too much).</p>

<syntax>
What are some syntax options for wildcard matching? (+ extensions)
CC BY-SA 4.0
2024-03-29T06:59:10.810Z
Is this about paths or strings? For paths, ** would also be common. I'd also rephrase it to uncommon ways, because, to me, your list looks already like obscure examples. "Glob" should also be clarified.
feldentm
CC BY-SA 4.0
2024-03-29T08:07:37.103Z
You say "alternation ... is too much",  but refer to the "extended glob syntax" found in bash, which implements a form of alternation. A simpler form based on list expansion is also common, e.g. [.editorconfig files](https://editorconfig.org/) allow `{foo,bar}` and `{1..9}`. I don't think there's a clear line between "extended glob-like matching" and "simple regex-like matching".
IMSoP
CC BY-SA 4.0
2024-03-29T14:37:42.710Z
@feldentm updated to clarify.
CoffeeTableEspresso
CC BY-SA 4.0
2024-03-29T14:37:47.740Z
@IMSoP you are right that there's no clear line, e.g. the extended glob I linked earlier has alternation, whereas some regex-style patterns (e.g. in Lua) don't have any alternation.  Maybe I should edit to allow any extensions to wildcard matching.
CoffeeTableEspresso
CC BY-SA 4.0
2024-04-17T13:50:16.470Z
Globs are a sort of "first-order" regular expression. `?` is `.`, `*` is `.*`, but `[...]` is limited to alternating individual characters, not arbitrary "subglobs". `bash` extended globs remedy that, and so are equivalent to regular expressions in power. (Ranges and negation are just shortcuts for explicit alternation.)
chepner
# What are some syntax options for wildcard matching? (+ extensions)
Posted by: username_0 on 2024-03-29
By "wildcard matching" I mean the following:

* `*` matches zero or more of any characters. E.g. `B*` matches any string starting with `B`, including just `B`.
* `?` matches any one character. E.g. `???` matches any string that is exactly three characters long.
* `[abc]` matches any of the enclosed characters (with a few exceptions noted below). E.g. `[HCB]at` matches `Hat`, `Cat`, or `Bat`.
* `[x-y]` matches any character in the specified range. E.g. `[0-9]` matches any digit.
* `[^...]` negates the character class. E.g. `[^0-9]` matches any non-digit character.

The above is the syntax commonly used in tools like `glob` (which also usually have a few path-specific features not mentioned above). SQL also supports similar, but using `%` instead of `*`, and `_` instead of `?`.

I don't care about path-specific variants or extensions such as path separators, `**`, or ignored leading `.`, this is focused on string matching specifically.

Some variants I found already:

* [At least one database](https://learn.microsoft.com/en-us/office/vba/access/concepts/structured-query-language/like-operator-microsoft-access-sql) supports `#` as a synonym for `[0-9]`.
* Bash supports an [extended version of globbing](https://www.linuxjournal.com/content/bash-extended-globbing), using syntax like `?(...)` (one or zero of the enclosed patterns), `*(...)` (zero or more of the enclosed patterns), etc. (Bash also supports more complex extensions such as alternation, which is closer to regex and hence a little beyond the scope of this question.)
* Many glob and SQL implementations support `[!...]` for negation of a character class instead of/in addition to `[^...]`.

So, my question is, are there any other syntax options for this? And are there any other extensions I'm not aware of here? I'm not looking for something as complex as a regex here (e.g. alternation, backtracking or similar is too much).
**Tags:** syntax
> **Comments:**
> **username_1**: Is this about paths or strings? For paths, ** would also be common. I'd also rephrase it to uncommon ways, because, to me, your list looks already like obscure examples. "Glob" should also be clarified.  
> **username_2**: You say "alternation ... is too much",  but refer to the "extended glob syntax" found in bash, which implements a form of alternation. A simpler form based on list expansion is also common, e.g. [.editorconfig files](https://editorconfig.org/) allow `{foo,bar}` and `{1..9}`. I don't think there's a clear line between "extended glob-like matching" and "simple regex-like matching".  
> **username_0**: @feldentm updated to clarify.  
> **username_0**: @IMSoP you are right that there's no clear line, e.g. the extended glob I linked earlier has alternation, whereas some regex-style patterns (e.g. in Lua) don't have any alternation.  Maybe I should edit to allow any extensions to wildcard matching.  
> **username_3**: Globs are a sort of "first-order" regular expression. `?` is `.`, `*` is `.*`, but `[...]` is limited to alternating individual characters, not arbitrary "subglobs". `bash` extended globs remedy that, and so are equivalent to regular expressions in power. (Ranges and negation are just shortcuts for explicit alternation.)  
---
## 0 answers
