I am working on a Java program that replaces variable values in a text file.
The variables to be replaced are encapsulated as...
side /*{{*/ red /*TEAM}}*/
or
detect_range /*{{*/ 200 /*RANGE}}*/ nm
So in the first case I want to replace the value red with another value. The second I would replace 200.
Here I am reading the file line by line looking for that pattern.
File file = new File(currentFile);
try {
Scanner scanner = new Scanner(file);
int lineNum = 0;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lineNum++;
if (<match regex expression for xxxxx /*{{*/ value /*VariableNAME}}*/ >) {
}
}
} catch (Exception e) {
System.out.println(e.toString());
//handle this
}
What is a regex expression to that I Could use to find these patterns?
Edit:
I have a line in the file that would say
side /*{{*/ red /*TEAM}}*/
The output change the line in the file to
side /*{{*/ blue /*TEAM}}*/
The string "TEAM" is the identifier.
/* */pairs, are they part of the pattern, or just comment markers?TEAMandRANGEare dynamic value?