help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is wrong with a regex?


From: Leonid Isaev
Subject: Re: What is wrong with a regex?
Date: Sat, 4 Feb 2023 05:06:11 +0000
User-agent: Mutt/1.13.4 (2020-02-15)

On Fri, Feb 03, 2023 at 10:08:29PM -0600, Dennis Williamson wrote:
> Bash (and grep) don't allow an empty subexpression.
> 
>  f=foo; [[ $f =~ (|o) ]]; echo $?; echo "${BASH_REMATCH}"
> 2
> 
> $ echo foo | grep -E '(|o)'
> grep: empty (sub)expression

I must be missing something, but
-----8<-----
I-orca--05:01-~-> bash --version
GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

I-orca--05:02-~-> f=foo; [[ $f =~ (|o) ]]; echo $?
0

I-orca--05:03-~-> grep -E "(|o)" <<< foo
foo

I-orca--05:03-~-> grep --version
grep (GNU grep) 3.4
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
----->8-----
WTF?

-- 
Leonid Isaev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]