Replacing illegal character in fileName

后端 未结 7 1940
情书的邮戳
情书的邮戳 2020-12-24 10:39

In Java, I\'ve a File-Name-String. There I want to replace all illegal Characters with \'_\', but not a-z, 0-9, -,. and <

7条回答
  •  情歌与酒
    2020-12-24 11:15

    You need to replace everything but [a-zA-Z0-9.-]. The ^ within the brackets stands for "NOT".

    myString = myString.replaceAll("[^a-zA-Z0-9\\.\\-]", "_");
    

提交回复
热议问题