删除特定字符后的下一个字母?

时间:2022-09-13 09:31:39

So what i'm asking for is a thing that does as following: I have this character: "&" The following character could be anything, so it could look like this: &1, &2, &3, &4, &5, &6, &7, &8, &9, &0, &a, &b, &c, &d, &e,& &f, &r - How would I remove those without hardcoding it? Like if its &3 it would just remove it and if its &1 somewhere else it would remove that.

所以我要求是一件事:我有这个角色:“&”下面的字符可以是任何东西,所以它可能是这个样子:& 1,2,3和4,第5号6 & 7,8条,和9,四维,,,和,魅,明目的功效,研发,机电,& f描述:——我怎么删除那些没有硬编码吗?就像如果它是3,它会把它移开,如果它和1在别的地方它会把它移走。

1 个解决方案

#1


2  

You can use a very basic regular expression with a placeholder for any character (single character as I understand in this case).

您可以使用一个非常基本的正则表达式,并为任何字符使用占位符(我在本例中理解为单个字符)。

System.out.println("&xx&y".replaceAll("&.", "")); // prints the middle "x" only

See API here.

在这里看到的API。

#1


2  

You can use a very basic regular expression with a placeholder for any character (single character as I understand in this case).

您可以使用一个非常基本的正则表达式,并为任何字符使用占位符(我在本例中理解为单个字符)。

System.out.println("&xx&y".replaceAll("&.", "")); // prints the middle "x" only

See API here.

在这里看到的API。