I'm running a reasonably up-to-date Msys2:
$ uname -a; bash -version
MSYS_NT-10.0-26100 md2syz7c 3.6.6-2369286a.x86_64 2026-01-14 12:29 UTC x86_64 Msys
GNU bash, version 5.3.9(1)-release (x86_64-pc-cygwin)
I'm confronted with a third-party script which tries to match a string which may be empty. The simplified version is:
[[ 0 =~ ^(0|)$ ]] && echo match
The goal is to match single zeroes or the empty string (note the ^ and $ anchors, otherwise an empty alternative would match anything). This works as expected under old and new gnu/Linuxes (e.g. GNU bash, version 4.4.12(1)-release (i686-pc-linux-gnu), or GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu), as well as under cygwin CYGWIN_NT-10.0-26100 md2syz7c 3.4.6-1.x86_64 2023-02-14 13:23 UTC x86_64 Cygwin.
However, it does not work with the recent Msys2 with the specs mentioned at the top:
$ [[ 0 =~ ^(0|)$ ]] && echo match
-bash: [[: invalid regular expression `^(0|)$': empty (sub)expression
Question: Should it work? (Is this a legit regular expression?) If yes, is this a known bug in Msys2's bash?
https://shellcheck.net, a syntax checker, or installshellchecklocally. Make usingshellcheckpart of your development process.