rohankanojia

Untitled

Sep 28th, 2020
1,041
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.regex.Matcher;  
  2. import java.util.regex.Pattern;  
  3.  
  4. public class DockerArgRegex {
  5.     public static void main(String[] args) {
  6.         System.out.println(extract("$foo"));
  7.         System.out.println(extract("${foo}"));
  8.     }
  9.  
  10.     private static String extract(String input) {
  11.         Pattern argPattern = Pattern.compile("\\$(?:\\{([^{}]+)\\}|(\\w+))");
  12.         Matcher matcher = argPattern.matcher(input);
  13.         if (matcher.find()) {
  14.             return (matcher.group(1));
  15.         }
  16.         return null;
  17.     }
  18. }
RAW Paste Data