Java 如何在map-reduce程序中替换输入字符串中的特殊字符

Java 如何在map-reduce程序中替换输入字符串中的特殊字符,java,mapreduce,Java,Mapreduce,我能够替换普通java程序中的特殊字符 这是我的java代码: public class A { public static void main(String[] args) { String s = "This785($^#')\""; System.out.println(s); s=s.replaceAll("[^\\w\\s]", ""); System.out.println(s); } 但我在我的map reduce程序中也尝试了同样的方

我能够替换普通java程序中的特殊字符

这是我的java代码:

public class A {

    public static void main(String[] args) {
    String s = "This785($^#')\"";
    System.out.println(s);
    s=s.replaceAll("[^\\w\\s]", "");
    System.out.println(s);

}
但我在我的map reduce程序中也尝试了同样的方法,但这不起作用

 public static class Map extends MapReduceBase implements
        Mapper<LongWritable, Text, Text, IntWritable> {

    @Override
    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter)
            throws IOException {

        String s = value.toString().replaceAll("\\w+\\s+","");
        String[] words=s.split(" ");
        for(String a:words){


output.collect(new Text(a),new  IntWritable(1));
        }
    }
map-reduce程序的输出

   "This@#$ is$# word$%^ (Count)"
  "This@#$ is$# word$%^ (Count)"
 "This@#$   2
  (Count)"  2
    is$#    2
 word$%^    2

我做错什么了吗?请帮帮我

您的正则表达式已从
[^\\w\\s]
更改为
\\w+\\s+

这个正则表达式意味着,匹配一个或多个字母(a-z/a-z)或数字(alpha-numberic),后跟空格、制表符或新行等,并用空字符串替换它。您的字符串中有:

 "This@#$ is$# word$%^ (Count)"
您不满足大小写,因此输出不满足。您可以使用$或#或^后跟空格,但不能使用字母数字字符后跟空格