Java替换正则表达式无法正常工作 [英] Java Replace Regex not working

查看:143
本文介绍了Java替换正则表达式无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这行代码不起作用?它应该用什么都不替换所有的标点符号。

Why doesn't this line of code work? It's supposed to replace all the punctuations with nothing.

m = m.replace("[\\?\\.;:'\"]", "")

m执行此操作后不会改变java中的行,即使它包含标点符号。为什么?

m will not change after executing this line in java even though it contains punctuations. Why?

推荐答案

这是因为 replace 需要字符串;您需要调用 replaceAll ,它确实采用正则表达式。

This is because replace takes a String; you need to call replaceAll, which does take a regular expression.

这篇关于Java替换正则表达式无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆