简体   繁体   中英

regular expression to get string in between special charecters

Iam trying to get the string october from the string ["october"] i tried with replace method

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

i cant replace quote with "" .

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

not replacing quotes prints \\"october\\"

But i prefer to use a single code

using regex code how can i get the string with out quotes and square bracket

You need to slightly correct your regex. You haven't put any rule for removing double quote. Try using this,

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

Refer Java replace all square brackets in a string

Removing double quotes from a string in Java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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