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

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



On Oct 20,  8:09pm, Stephane Chazelas wrote:
} Subject: Re: Issue with ${var#(*_)(#cN,M)}
}
} 2015-10-19 12:17:28 -0700, Bart Schaefer:
} > 
} > } ~$ a='1_2_3_4_5_6'
} > } ~$ echo ${a#(*_)(#c2)}
} > } 2_3_4_5_6
} > 
} > Here, it first matched "1_2_3_4_5_" but then couldn't match a second
} > time, so it backtracked, matched "1_", and stopped counting.
} 
} Note that the:
} 
} ~$ echo ${a#*_*_}
} 3_4_5_6
} ~$ echo ${a#*_*_*_}
} 4_5_6
} 
} work OK.

Well, yes, but not really relevant.

} And also:
} 
} ~$ echo ${a#(*_)(*_)(*_|)}
} 3_4_5_6

The (#c) modifier is not implemented by replicating the pattern, it's
implemented by counting the number of successful trials that can be
made using the single pattern.  So it really makes no difference to
the bug that manually repeating the pattern does the right thing.

What's messing it up is the "*" operator and the backtracking that is
implied because * can match anything.



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