0

I wanted to extract what ever is within the below tokens

${FNAME} ${LNAME} ${123}

FNAME LNAME 123.

I tried the below.

public static void main(String[] args) {

    String input = "{FNAME} ${LNAME} ${123}";

    Pattern p = Pattern.compile("\\$\\{");
    Matcher m = p.matcher(input);


    while (m.find()) {
        System.out.println("Found a " + m.group() + ".");

    }

}

Ended up wrongly. Beginner to reg expressions.

user3362080
  • 301
  • 1
  • 4
  • 10

1 Answers1

1

You should use lazy quantifier ? and capture group () like this.

Regex: \$\{(.*?)\}

Replacement to do: \1 for first captured group.

Regex101 Demo