What's the problem? On wsl2 Ubuntu egrep, presumably from open source, says:
dgp:~$ egrep '^1[2,3]2$' <<!1221321213232233!122132dgp:~$
On Wednesday, October 1, 2025 at 03:49:59 PM EDT, Paul Eggert
<[email protected]> wrote:
The behavior you describe is documented and is not a bug; see:
https://www.gnu.org/software/grep/manual/html_node/Problematic-Expressions.html
and look for "In an extended regular expression, unescaped ‘{’ that does
not begin a valid interval expression."
Here are some more details about this portability issue.
On 2025-10-01 06:35, Bob Peraino wrote:
> ^1{2,3]2$
Because this ERE has an unmatched brace, POSIX says that grep produces
undefined results for it; see
<https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap09.html#tag_09_04_03>,
which talks about what happens "If a <left-brace> is not part of a valid
interval expression".
> The Mac version of grep (AT&T origin) properly flags this:
>
> % egrep '^1{2,3]2$'
> egrep: invalid repetition count(s)
Although the macOS behavior conforms to POSIX, I don't think it is AT&T
origin. Traditional egrep behaves like GNU grep -E. You can see this,
for example, in Solaris 10 egrep, which is closer to the AT&T tradition
than macOS egrep is. The traditional behavior also conforms to POSIX
since POSIX says grep can do whatever it likes.
Traditional egrep and GNU grep -E are more likely to do the intended
thing when a user mistakenly thinks that '{' is an ordinary character.
macOS egrep diagnoses this use of an unportable ERE that could well be a
typo. Neither approach strictly dominates the other.