java 正则表达式从java中的字符串中删除空格,逗号,空格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12470496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:02:13  来源:igfitidea点击:

Regular Expression to remove space ,comma ,space from a string in java?

javaregex

提问by Sandeep Sokhal

i Have a string s "hello,sa n.txt"

我有一个字符串“你好,sa n.txt”

but i want the string s ="hellosan.txt" no comma,no space, no semicolon,should be there How can i do this in java Using regular expression?

但我想要字符串 s ="hellosan.txt" 没有逗号,没有空格,没有分号,应该在那里我如何在 java 中使用正则表达式来做到这一点?

回答by Bohemian

String input = "hello,sa n.txt";
String clean = input.replaceAll("[, ;]", ""); // replace any of ", ;" with "nothing"

回答by nmenego

Try this to replace ALL of the commas, semicolons and spaces in your string:

试试这个来替换字符串中的所有逗号、分号和空格:

replaceAll("[,;\s]", "");

回答by PermGenError

    System.out.println("hello,sa n.txt".replaceAll("[, ;]", ""));