Regex QA check - Grouped Search Expressions

Hi,

I have a project containing many occurrences of this type of pattern (any letter A-Z, and a +/- sign in brackets; with multiple pairs of this pattern per segment):

" ... between A(+) and B(-) and between F(+) and C(-)"

I'm using Studio 2019 and I've tried to set up a Regex check in the QA checker, using a Grouped Search Expression (source matches but not target), but I get an error message and don't know why.

Here's what I've tried:

Source (all of these patterns work when I test them in the search box of the Community Advanced Display Filter and in a third-party regex checker):

  • [A-Z]\(\W\)
  • [A-Z]\(.\)
  • [A-Z]\([\+-]\)

Target:

  • $0

However, when I confirm a segment with this pattern in, I get this error message:

Can anyone see what I'm doing wrong here?

Thanks,

Hayley

Parents
  • Can't test it now, but I think that it should work if you change

    the source regex to:

    [A-Z]\((\W)\)

    and the target regex to:

    $1

    The source regex still needs the unescaped parentheses to set the group and then backreference it with number $1 in the target regex (although $0 might work as well…).

  • Hi Jésus,

    Thanks for the quick reply. I tried your suggestion, and it worked in part: it correctly flags up a missing (+) or (-) in the target. However, it doesn't spot an incorrect letter, because (if I understand correctly) the $1 only captures and checks for the part in brackets.

    I thought $0 meant "capture all of the source expression", so I tried putting that in the target box, but that flagged up every matching pattern in the source as "missing" in the target, even though they were all present and correct.
    I then tried ([A-Z])\((\W)\) as the source, and $1$2 as the target, but that did the same: flagged everything as missing even when it was present.

    I suppose I could set up a second, separate, grouped Regex to check single capital letters, but if there's something that can combine the two, that would be better!

    So I'm still searching...

    Hayley

  • OK, if you also need to check the character before the parentheses, then this source regex should work:

    ([A-Z])(\(\W\))

    with the target regex you mentioned:

    $1$2

  • Thanks again for your help! For info/for anyone else reading this, I posted the same question in another forum, and somebody there suggested an alternative version, which also works:

    Source: ([A-Z]\([\+-]\))

    Target: $0

  • Yeah, there are usually several regexes.

    I even think your latest regex can be simplified to

    ([A-Z]\([+-]\)) with the same target regex,

    and even to:

    [A-Z]\([+-]\)

    and don't use a grouped regex at all.

Reply Children
No Data