I'm trying to get anything inside {{{#!MyTestMacro
and }}}
using java regex groups, couldn't get there. Basically I want to remove {{{#!MyTestMacro
and }}}
which surrounds the content inside it.
Below is my code snippet.
File file = new File("mytestfile.txt");
FileInputStream fis = new FileInputStream(file);
byte[] data = new byte[(int) file.length()];
fis.read(data);
fis.close();
String str1 = new String(data, "UTF-8");
String pattern = "\\{\\{\\{\\s*#!MyTestMacro(.*?)\\}\\}\\}";
Pattern r = Pattern.compile(pattern, Pattern.MULTILINE);
Matcher m = r.matcher(str1);
if (m.find()){
System.out.println("Found value: " + m.group(0));
System.out.println("Found value: " + m.group(1));
} else {
System.out.println("NO MATCH");
}
str1 = str1.replaceAll(pattern, m.group(1));
System.out.println(str1);
Input:
{{{#!MyTestMacro
My desired content.
My desired content2.
}}}
Expected Output:
My desired content. My desired content2.