How do I use regex to capture, say, every run of space characters \ + inside brackets? For example, in the string,
"abc and 123 {foo-bar bar baz } bit {yummi tummie} byte."
I should find four matches inside {} -- but nothing else. Assume Python language and that the string content is unknown.
EDIT: Also assume that there are NO nested braces.
A lookahead can check if there is a } ahead without any { in between.
\s+(?=[^{]*})
\s is a short for whitespace character [ \t\r\n\f]. Match + one or more.
(?=[^{]*}) looks ahead if there is a } with any non { in between.
Demo at regex101
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With