Ask Your Question
1

How to match all characters between curly braces, provided that a specific string is present through Regex?

asked 2021-04-29 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-07-29 11:00:00 +0000

lakamha gravatar image

To match all characters between curly braces provided that a specific string is present, you can use the following regular expression:

/\{\s*(specific_string)(.*?)\s*\}/s

In this expression, replace specific_string with the actual string that you want to match. The .*? matches any character (excluding newlines) zero or more times, but as few times as possible, until it reaches the closing curly brace.

Here's a breakdown of the expression:

  • \{ matches the opening curly brace
  • \s* matches zero or more whitespace characters
  • (specific_string) matches the specific string you want to find
  • (.*?) matches any character, but as few times as possible, until it reaches the closing curly brace
  • \s* matches zero or more whitespace characters
  • \} matches the closing curly brace
  • /s enables the "dotall" mode, which allows the . character to match newlines as well as other characters
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-04-29 11:00:00 +0000

Seen: 9 times

Last updated: Jul 29 '21