I’m looking for the regex to match any string that has an opened or closed curly bracket. It should only match when there is another character besides space, tab, etc (\s) within the brackets – even if there is another bracket in the string.
Basicly this is part of a static code analyser witch should check if the bracket is on a new and blank line (style guide). If there is any other character in the string it should match.
I got this ^[\S]*({|})[\S]*$. But it also matches { because of the *.
I am using C#.
Example:
Match: { lala, lala{, asdf{asdf, {}
No Match: {, {, },TAB { TAB, asdf
Thanks!
Regex
^(?=.*[{}])\S*$would match string that contains at least one curly bracket and such string would not have any whitespace characters.Update:
Based on you comments you might be looking for this regex:
.*{(?:\s*[^\s}]+}?|})