0

I have two types of input string:

${place.holder}
${place.holder:defValue}

I need to extract only place.holder whether it has a :defValue or not, i.e. desired result in both cases should be:

place.holder
place.holder

This is the full match: https://regex101.com/r/hjWEO1/1/ I've tried negative lookahead, but it matches omly first symbol in group.

gorodkovskaya
  • 333
  • 3
  • 15
  • 1
    Add `?` after a group that must be optional. See [this demo](https://regex101.com/r/hjWEO1/2). A `\${([^{}:]*(?::[^{}]*)?)}` [regex](https://regex101.com/r/hjWEO1/3) might be a bit better here, but that is not relevant for the current problem. – Wiktor Stribiżew Jan 18 '19 at 09:09
  • @WiktorStribiżew I updated my question: I don't need `:defValue` to be included too – gorodkovskaya Jan 18 '19 at 09:14
  • 1
    Then use `(\$\{)(.*?)(?:\:.*)?(\})` or `\${([^{}:]*)(?::[^{}]*)?}` – Wiktor Stribiżew Jan 18 '19 at 09:15

0 Answers0