繁体   English   中英

正则表达式以在特殊字符之间获取字符串

[英]regular expression to get string in between special charecters

我试图从替换["october"]字符串中获取字符串october

 tagNo = tagNo.replaceAll("\\[|\\]", ""); \\ it prints "october"

我无法将引号替换为""

 tagNo = tagNo.replaceAll("\\[|\\]", "").replaceAll("\"", "\\\\\"");

不替换报价打印\\"october\\"

但我更喜欢使用一个代码

使用regex代码如何获取不带quotessquare bracket的字符串

您需要稍微更正您的正则表达式。 您尚未制定任何删除双引号的规则。 试试这个

tagNo = tagNo.replaceAll("(\\[|\"|\\])+", "");
 tagNo = tagNo.replaceAll("[^a-zA-Z]+","");
 tagNo = tagNo.replaceAll("\\[\"", "");
 tagNo = tagNo.replaceAll("\"\\]", "");

引用Java替换字符串中的所有方括号

在Java中从字符串中删除双引号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM