Re: Word boundary anchors \< and \> not parsed correctly on the right si
From:
Ilkka Virta
Subject:
Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~
Date:
Tue, 10 Jul 2018 15:52:22 +0300
User-agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.0
On 10.7. 15:27, Greg Wooledge wrote:
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.
Or does it use the system's regex library, whatever that supports?
On my Linux systems, this prints 'y' (with Bash 4.4.12 and 4.1.2):
re='\<foo\>' ; [[ "foo bar" =~ $re ]] && echo y
If '\<' matches just a regular less-than sign (but has a useless
backslash), then surely that should not match?
That's the same example marcelpaulo@gmail.com had, they didn't have
the <> signs in the string.
On my Mac, the above doesn't match. The same thing with a similar regex
with \w .
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.