I'm trying to extract Dockerfile ARG values which are usually of these forms:
$foo, expected output: foo
${foo}, expected output: foo
I want to capture the string after $. I'm trying this regex right now but it doesn't seem to working for second test case with curly braces:
private static String extract(String input) {
Pattern argPattern = Pattern.compile("^\\$([^{}]+)$");
Matcher matcher = argPattern.matcher(input);
if (matcher.find()) {
return (matcher.group(1));
}
return null;
}
Could anyone please tell me what I'm missing here?
{and}? Only letters, digits,_or more?_[^{}]in my solution below can be replaced with another\w.