[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Word boundary anchors \< and \> not parsed correctly on the right si
From: |
Greg Wooledge |
Subject: |
Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~ |
Date: |
Tue, 10 Jul 2018 08:27:18 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Mon, Jul 09, 2018 at 10:46:13PM -0300, marcelpaulo@gmail.com wrote:
> Word boundary anchors \< and \> are not parsed correctly on the right side of
> a =~ regex match expression.
Bash uses ERE (Extended Regular Expressions) here. There is no \< or \>
in an ERE.
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04
> This evaluates as false:
>
> [[ 'foo bar' =~ \<foo\> ]]
Well, of course it does, because \< is just a literal less-than sign
in a POSIX ERE.
wooledg:~$ re='\<foo\>'
wooledg:~$ [[ '<foo>' =~ $re ]] && echo yes
yes
You might as well remove the backslashes, because they serve no purpose
here. If you thought they meant "word boundary" or something, you're
in the wrong language.
Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~, Chet Ramey, 2018/07/10