Skip to content
Advertisement

Remove a pattern from a String containing varying alphanumeric

I am getting a String like below:

...,{foo.....}","gm:every":["one:varyingalphanumberic193alpha"],"{bar...},....

Now, checking if Pattern exists in the string, I want to get rid of this pattern – "gm:every":["one:varyingalphanumberic193alpha"], so that my string becomes:

...,{foo.....}","{bar...},....

I tried to follow this – How to remove a particular pattern from a String in Java? but in my case the given pattern can be anywhere in the string and also contains varying alpha-numeric characters. Feeling clueless on how to compile it. Any pointer in this regard, will be greatly appreciated.

Advertisement

Answer

String text = "...,{foo.....}","gm:every":["one:varyingalphanumberic193alpha"],"{bar...},....";

text = text.replaceAll(""gm:every":\["one:[\s\S]*],", "");

System.out.println(text);
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement