|
From: | Ilkka Virta |
Subject: | Re: Incorrect example for `[[` command. |
Date: | Sat, 21 Sep 2019 22:15:05 +0300 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 |
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.htmlThis 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
[Prev in Thread] | Current Thread | [Next in Thread] |