Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Issue with ${var#(*_)(#cN,M)}



2015-10-27 11:03:53 +0000, Stephane Chazelas:
[...]
> ksh93 is also fine with it:
> 
> $ a='1_2_3_4_5'  ksh -c 'echo "${a#{2}(*_)}"'
> 3_4_5
> $ a='1_2_3_4_5'  ksh -c 'echo "${a##{2}(*_)}"'
> 5
> 
> The zsh limitation should probably be documented if not fixed.
[...]

Another work around is to use zsh's PCREs:

$ a='1_2_3_4_5'  zsh -o rematchpcre -c '[[ $a =~ "(?s)^(.*?_){2}" ]] &&echo $MATCH'
1_2_

$ a=$'1_2_3_4_5\nqweq'  zsh -o rematchpcre -c '[[ $a =~ "(?s)^(?:.*?_){2}(.*)" ]]; echo $match'
3_4_5
qweq

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author