A
A
alex4answ2020-06-23 14:31:03
Regular Expressions
alex4answ, 2020-06-23 14:31:03

Regular expression to search for {text} but ignore {{text}}?

Good afternoon, I can’t compose a regular expression that will search in the text:
{text}, but ignore {{text}} {{{text}}} and so on, you only need 1 bracket around the edges.

Now my regex is this:
{(\w+)}
But the problem is that it finds an extra

one. How to exclude from the selection cases when there are more brackets than specified?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-06-23
@alex4answ

(?<!\{)\{(\w+)\}(?!\})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question