I know this question has been asked many times on Stack Overflow but regex is too hard to understand.
What I tried:
String sentence = "The #{adjective} brown fox jumps over the lazy dog";
String requierd_sentence = sentence.replaceAll("[{*.*}]", "quick");
System.out.println(requierd_sentence);
Here in this sentence, adjectives are not at fixed position — they change with every new string/sentence. What I need to do is, replace the adjective with required string which is available in another column besides the sentence column. So fetching the string from column is OK, but regex matching is failing on many attempts.
What would be the correct regex for #{any string}?
- Sample output for above string would be =
The quick brown fox jumps over the lazy dog. - Another example input,
All that #{adjective} is not goldshould outputAll that glitters is not gold.
Now both sentences above have #{adjective} on different positions of the sentence, so I can't use split. I have to use a regex pattern.
[and{:sentence.replaceAll("\\[\\{*.*}]", "quick");.