I am getting unexpected matches when using the following regex: ^[^\{]*\{[^\{]*$
My intention is to match segments that contain exactly one{ character. To enforce this, I am using ^ and $ to anchor the pattern to the beginning and end of the segment.
For some reason, though, this doesn’t seem to be working as you can see in the second match below.
My expectation is that this segment should not be matched at all. Instead, Xbench appears to be matching only a substring of the segment, and I am struggling to understand why.
Could someone clarify this behavior? Is Xbench evaluating the regex against the entire segment, or can it match substrings even when ^ and $ are used?
@Des The highlighting of the second segment can be improved, but the segments match your expression, so search is working well.
Could you please give some examples of segments that you want to find with your expression? Per your description it seems that you are looking for segments that only have one single character, and that that character is { so the the total length of segment would be 1.
I’m looking to match segments that contain one and only one { character. The first segment in the screen fits this description. The second doesn’t (contains multiple { characters, and seem to be matching only the last { character, “ignoring” the start of segment part of the expression).
I would perhaps lean towards this expression: \{ -"\{.*\{" with both Regex and PowerSearch enabled.
The first part (\{) gets the subset of segments that have at least one open brace bracket and second part (-"\{.*\{") excludes those segments from the subset that have at least two brackets.
However, your expression should not match the second segment, so we will review that.