R
robincurts at gmail dot com
I won't pretend that I know what I'm doing with regular expressions. I
have a string that I want to take a chunk out and replace it with a
system property. So I might have app.home as a System property with
the value "/opt/application/" and I want to have a method that takes:
"$app.home/config/" and turns it into "/opt/application/config/"
I am not necessarily committed to using a $ like a scripted variable --
I have tried some other things, like @app.home@/config/ and
${app.home}/config/ -- but my regex is never correct. Here is the
test code I was using for the $app.home I was trying.
I hope someone can see something I'm missing.
Cheers,
Robin
public class EnvRE {
String s1 = "this/has/$variables.inside/of/it";
static final String RE = "^(?:.*?)(\\$[\\d\\w\\.]+?)(?:.*?)$";
public EnvRE() {
Pattern p = Pattern.compile(RE);
Matcher m = p.matcher(s1);
System.out.println("ORIGINAL: " + s1);
if (m.find()) {
for (int i = 0; i < m.groupCount(); i++) {
System.out.println("GROUP " + i + ": " + m.group(i));
}
}
}
public static void main(String[] args) {
new EnvRE();
}
}
Here's my output when I run this:
ORIGINAL: this/has/$variables.inside/of/it
GROUP 0: this/has/$variables.inside/of/it
have a string that I want to take a chunk out and replace it with a
system property. So I might have app.home as a System property with
the value "/opt/application/" and I want to have a method that takes:
"$app.home/config/" and turns it into "/opt/application/config/"
I am not necessarily committed to using a $ like a scripted variable --
I have tried some other things, like @app.home@/config/ and
${app.home}/config/ -- but my regex is never correct. Here is the
test code I was using for the $app.home I was trying.
I hope someone can see something I'm missing.
Cheers,
Robin
public class EnvRE {
String s1 = "this/has/$variables.inside/of/it";
static final String RE = "^(?:.*?)(\\$[\\d\\w\\.]+?)(?:.*?)$";
public EnvRE() {
Pattern p = Pattern.compile(RE);
Matcher m = p.matcher(s1);
System.out.println("ORIGINAL: " + s1);
if (m.find()) {
for (int i = 0; i < m.groupCount(); i++) {
System.out.println("GROUP " + i + ": " + m.group(i));
}
}
}
public static void main(String[] args) {
new EnvRE();
}
}
Here's my output when I run this:
ORIGINAL: this/has/$variables.inside/of/it
GROUP 0: this/has/$variables.inside/of/it