使用正则表达式从字符串中删除方括号? [英] Remove square brackets from a String using Regular Expressions?

查看:253
本文介绍了使用正则表达式从字符串中删除方括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Java中的给定字符串中删除所有方括号([])?

How would I remove all square brackets ("[]") from a given String in Java?

String s = "[abcdefg]";
s = s.replaceAll(regex, "");

在这种情况下会使用什么正则表达式?

What regular expression would be used in this case?

推荐答案

使用这个:

 String s = "[abcdefg]";
 String regex = "\\[|\\]";
 s = s.replaceAll(regex, "");
 System.out.println(s);

这篇关于使用正则表达式从字符串中删除方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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