1

I want to accomplish this:

setopt HIST_SUBST_PATTERN
echo Ninja_Turtles_2003_S02E05_DVDRip_30NAMA.mkv
^E(0?)^E$((match[1]+1))
# resulting in:
echo Ninja_Turtles_2003_S02E06_DVDRip_30NAMA.mkv

‌But I get:

echo Ninja_Turtles_2003_S02E1_DVDRip_30NAMA.mkv

I tried ^(#b)E(0?)^E$((match[1]+1)), but it didn't work.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
HappyFace
  • 1,493
  • 9
  • 21

1 Answers1

1

You need the extendedglob option for (#b).

Also 05 + 1 yields 6, not 06.

You could do (with extendedglob and histsubstpattern)

^(#b)E(<->)^E${(l:2::0:)$((match[1]+1))}

Or:

echo ${_//(#b)E(<->)/${(l:2::0:)$((match[1]+1))}
  • <-> is a form of <x-y> positive decimal number matching operator where both boundaries are omitted, so matches any non-empty sequence of decimal digits. Same as [0-9]## (though ## needs extended-glob while <x-y> doesn't).
  • (l:2::0:) (note that it's a lower case L, not the 1 digit) is the left-padding parameter expansion flag, here with 0s, of length 2.
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501