1
String text = the property value [[some.text]] and [[value2.value]]should be replaced.

The values [[some.some]] should be replaced with some dynamic code.

String entryValue = entry.getValue();           

            Pattern pattern = Pattern.compile("([[\\w]])");
            Matcher matcher = pattern.matcher(entryValue);

            while(matcher.find()){

             String textToReplace = matcher.group(1);
             textToReplace = textToReplace.replace(".","");

             String resolvedValue =   "text to be replaced";
             matcher.replaceAll(resolvedValue);                 
            }

1 Answer 1

1

Escape [ and ] as these are special regex symbols:

Pattern pattern = Pattern.compile( "(\\[\\[[\\w.]*\\]\\])" );
Sign up to request clarification or add additional context in comments.

10 Comments

Wouldn't you need two backslashes?
You don't need to escape ] id it doesn't have opened and unescaped [ before it.
@Pshemo: True but for readability purpose I always escape them.
Agree that it makes regex more readable. I just mention it as interesting additional info so others wouldn't be surprised that \[x] compiles fine.
That works. Thanks for your help. Can you just give a description of that regex?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.