Regex matching not enough digits -
when use regex pattern:
.*(?p<midinote>\d+)\.wav
on these strings, here :
[asr10] chr huge ahhs1.wav => midinote=1 ok [asr10] chr huge ahhs2.wav => midinote=2 ok [asr10] chr huge ahhs3.wav => midinote=3 ok [asr10] chr huge ahhs14.wav => midinote=4 not ok [asr10] chr huge ahhs15.wav => midinote=5 not ok [asr10] chr huge ahhs16.wav => midinote=6 not ok [asr10] chr huge ahhs127.wav => midinote=7 not ok
how catch ending numbers (1, 2, 3, 14, 15, 16, 127) keeping easy .*
@ beginning (for simplicity) ?
you should use word boundaries , anchor $
:
\b(?p<midinote>\d+)\.wav$
it because .*
greedy , without \b
matches more needed.
.*
not needed if must use then:
.*\b(?p<midinote>\d+)\.wav$
update: based on edited question there no word boundary before numbers, can use:
.*?(?p<midinote>\d+)\.wav$
i.e. make .*?
non-greedy.
Comments
Post a Comment