RegEx to identify unpaired parentheses (open but not closed) in target during QA

Hi everyone!

I don't know if it's possible to do what I want during QA. I'm trying to find unpaired parentheses, but only in the target.

Example: The sly fox (paragraph 5.3 went after the slow hare.

I did a couple of searches to test regex strings that I came up with, but ended up with too many false positives. These showed up, for example, every time that the source had parentheses and the target didn't.

I also tried using “check brackets” under punctuation in the QA Checker (so it wouldn't need regex). But that also gave the same false positives (the source had parentheses and the target didn't), as well as false positives when I had added parentheses of my own in the target.

Thanks in advance for your help!

best,

Becky

(I'm using Trados Studio 2022)

emoji
  •  

    Quite tricky... I can only do this with two expressions.  So for an unpaired opening parentheses try this:

    \((?![^()]*\))

    Then for an unpaired closing try this:

    (?<!\()(\))(?![^(]*\))

    Seems to work, but with very limited testing!

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  •  

    The opening parenthesys pattern works fine (and I even understand it Grinning), but the closing one does’t work in https://regex101.com/, as it matches the right pairs:

    Screenshot of regex101.com showing a regular expression pattern and test string with highlighted matching groups.

    It doesn’t work in Trados Studio either:

    Screenshot of Trados Studio with two warning icons indicating errors in the regular expression pattern.

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 4:50 AM (GMT 0) on 5 Mar 2024]
  • Hi dear Paul!

    Thanks so much for your help! The expression for unpaired opening parentheses works, since it did find them. 

    It also finds some false positives, such as when parentheses are nested within each other but paired correctly. For example: Find your grade (paragraph (b) and (d) in here) where it goes.

    I don't think that's a huge problem, since it would just make me double-check the parenths in those segments.

    As far as the unpaired closing, I don't think that the regex works all the time. But it's not as essential as the unpaired open. I think that's a more obvious mistake when I'm reviewing text visually. 

    As always, thanks so much for your help!

    best,

    Becky

    emoji
  •  

    After a year of this post, I’m back with it! Grinning

    The following regex works for both missing opening and closing brackets (it matches nested brackets, but they are rare avis and maybe wrong after all, so I’d check them):

    ^[^\(]*\)|\([^\)]*\(|\)[^\(]*\)|\([^\)]*$

    PS.: Borrowed from https://forum.xbench.net/t/need-more-unpaired-parenthesis-checks/106/5

    The logic behind is so easy that it’s possible to split the above regex in 4 separate rules easier to read while QA’ing:

    • ^[^\(]*\) to match an unpaired closing bracket at the beginning of the segment
    • \([^\)]*\( to match 2 consecutive opening brackets
    • \)[^\(]*\) to match 2 consecutive closing brackets
    • \([^\)]*$ to match an unpaired opening bracket at the end of the segment

    Tested with the following text here https://regex101.com/:

    RIGHT BRACKETS =========
    aa (bbbb)
    aa (bbbb) aa (bbbb)
    aa (bbbb) aa (bbbb) aa (bbbb)
    aa (bb (nested brackets))

    WRONG BRACKETS ==========
    aa bbbb)
    aa bbbb) aa (bbbb)
    aa (bbbb) aa bbbb)
    aa bbbb) aa (bbbb) aa (bbbb)
    aa (bbbb) aa bbbb) aa (bbbb)
    aa (bbbb) aa (bbbb) aa bbbb)

    aa (bbbb
    aa (bbbb aa (bbbb)
    aa (bbbb) aa (bbbb
    aa (bbbb aa (bbbb) aa (bbbb)
    aa (bbbb) aa (bbbb aa (bbbb)
    aa (bbbb) aa (bbbb) aa (bbbb

    emoji