Removing every other character in a string using Java regex

前端 未结 3 1230
一向
一向 2020-12-31 15:29

I have this homework problem where I need to use regex to remove every other character in a string.

In one part, I have to delete characters at index 1,3,5,... I hav

3条回答
  •  灰色年华
    2020-12-31 15:59

    Your regex needs 2 chars to match, so fails on the final char.

    This regex:

    ".(.{0,1})"
    

    Will make the second char optional, so it will match with your final '5' as well

提交回复
热议问题