Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class DockerArgRegex {
- public static void main(String[] args) {
- System.out.println(extract("$foo"));
- System.out.println(extract("${foo}"));
- }
- private static String extract(String input) {
- Pattern argPattern = Pattern.compile("\\$(?:\\{([^{}]+)\\}|(\\w+))");
- Matcher matcher = argPattern.matcher(input);
- if (matcher.find()) {
- return (matcher.group(1));
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment