Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15396

Re: Incorrect example for `[[` command.

From Ilkka Virta <itvirta@iki.fi>
Newsgroups gnu.bash.bug
Subject Re: Incorrect example for `[[` command.
Date 2019-09-21 22:15 +0300
Message-ID <mailman.743.1569093322.2190.bug-bash@gnu.org> (permalink)
References (1 earlier) <8e7c8ea4-2fdf-4809-0b50-ea1bfbbec165@case.edu> <CAD0rTC68qoXvCV9SLP1dJ8Gvg71W7bg9yt8jjpmpESK-jKD7Wg@mail.gmail.com> <bf5a1810-8316-239c-0c5a-f85803048ab6@iki.fi> <20190921185509.GA5480@madrid> <d90e728d-7e92-6c8f-2470-14326c8b2e87@iki.fi>

Show all headers | View raw


On 21.9. 21:55, Dmitry Goncharov wrote:
> On Sat, Sep 21, 2019 at 12:34:39PM +0300, Ilkka Virta wrote:
>> [[:space:]]*?(a)b  isn't a well-defined POSIX ERE:
>>
>>     9.4.6 EREs Matching Multiple Characters
>>
>>     The behavior of multiple adjacent duplication symbols ( '+', '*', '?',
>>     and intervals) produces undefined results.
>>
>> https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/basedefs/V1_chap09.html
> 
> This is unfortunate.
> *? and +? are widely used not greedy regexes.

In Perl-compatible regexes. Bash uses POSIX extended regular expressions.

And on a GNU system, while *? and +? don't give errors when used in an 
ERE, they still don't make the repetition non-greedy. They just act the 
same as a single * (as far as I can tell anyway).

  bash$ re='<.+?>'
  bash$ [[ "a<b>c<d>e" =~ $re ]] && echo $BASH_REMATCH
  <b>c<d>
  bash$ [[ "a<>e" =~ $re ]] && echo $BASH_REMATCH
  <>

-- 
Ilkka Virta / itvirta@iki.fi

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Incorrect example for `[[` command. Ilkka Virta <itvirta@iki.fi> - 2019-09-21 22:15 +0300

csiph-web