2
votes

I'm trying to capture: word {word} word.

I have the following regex: \S*\s\{.*?\}\S[^{\s]*

It actually captures this pattern, but it also captures word {word}. See: https://regex101.com/r/yI64KQ/6

How to fix it to only capture: word {word} word ?

Thank you very much in advance for all the people who help.

3
Is "[^{s]" meant to be "[^{\s]" (ie whitespace, not a literal "s")Bohemian
Sorry, I fix it. In fact, another user edit because I forgot `` to regex. It was worse.. LOLGleidson Henrique
The range A-z matches more characters than only letters. I suugest you to have a look at an ASCII table.Toto

3 Answers

1
votes

If I understand the problem right, we wish to capture the three words, which we can start with an expression similar to:

^(.+?)(\s+)?({(.*)?\})?(\s+)?(.+?)?$

Demo

enter image description here

1
votes

[RESOLVED]

Thanks to Norbert Incze, final regex is: ([A-zÀ-ú]+([^\S\n]+\{[^}]*\}[^\S\n]+[A-zÀ-ú]+)+)

This worked perfectly! Thanks to everyone who helped me.