-1

I am a newbie in regular expression, I have written regular expression for ${serviceName} basicly I want to take the words in between ${ } So I already wrote regular expression for this that is perfectly fine

"\\$\\{(\\w+)\\}"

But what I want to take any values not only the words which are in between ${serviceName.1.Type}.So can you guys help me with regular expression for ${serviceName.1.Type}. I hope my question is clear.

Thanks In Advance.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
user2911592
  • 91
  • 12

2 Answers2

0

A good place to test regular expressions is https://regex101.com/

\w+ matches any word character (equal to [a-zA-Z0-9_])

If you want to match anything you can replace it with: .*

.* matches any character (except for line terminators)

You might want to add a "?" at the end to match to first "}"

*? Quantifier — Matches between zero and unlimited times, as few times as possible, expanding as needed

Also you don't need to escape the { } in this case

So what you want is: "\\${(.*?)}"

Felipe Faria
  • 569
  • 1
  • 5
  • 13
  • Thanks so much that's what I am looking for. So mark this question as resolved. – user2911592 May 10 '20 at 11:26
  • Just one more question sorry for that .. What is the significance ? here. – user2911592 May 10 '20 at 12:19
  • I've edited to copy the definition of *? from regex101. If you had a line with `{ return "${Hello}"; }`. Then `"\\${(.*?)}"` will match `${Hello}` and `"\\${(.*)}"` will match `${Hello}"; }` – Felipe Faria May 11 '20 at 15:43
0

\$\{([\w?\.?\d?\s?]+)\}

This expression captures as a group everything that appears between {} You can then call the group with the expression $1

On this web you will see your exercise solved and if other expressions have some additional character you can try to add it. Now it is prepared for points \. , spaces \s, letters \w and digits \d

EBL
  • 71
  • 5