Aashish Nagar
Aashish Nagar

Reputation: 59

Regular expression for multiple matches between curly brackets

The server is sending a string that will have the key inside it. one string can have multiple key. I need to write a regular expression to extract the key. For example, if string coming from the server is

"{{call_started}} at 6.50 but the user was not available. {{
user_name}} must be offline. "

Here we have two key: call_started and user_name

in the incoming string, all key will start with {{ and end with }}.

How to write the regular expression for this.

Upvotes: 2

Views: 425

Answers (1)

Ambrish Pathak
Ambrish Pathak

Reputation: 3968

Use below regex:

\{\{(.*?)\}\}

By using above, Mactch 1 Group 1 will have call_started and Match 2 Group 1 will have user_name

This will match all the occurrences of {{ }}

See usage and explanation here https://regex101.com/r/CESeIy/1

Upvotes: 3

Related Questions