Custom regex needed

I need help scripting a regex that’ll detect when a key phrase ("# of") is present anywhere in a string, then followed by more than 1 set of parentheses.

The rules:

  1. The string must contain the phrase “# of”, where # is any digit [1 - 9].
  2. The string must contain more than 1 set of parentheses within the scope of the “# of” phrase.
  3. The key phrase may be nested, so its scope may be bounded.

Here’s my current regex attempt.

Here are the string examples, plus whether or not they should be matched.

"1 of Apple, Bat, Car, Dog, Ear" ---------------- NO – No sets detected
"3 of (Apple), Bat, Car, Dog, Ear" ------------- NO – Sets < 2.
"2 of (Apple), Bat, (Car), Dog, Ear" ---------- YES – Sets > 1.
"Apple, (Bat), Car, (Dog), Ear" ------------------ NO – Key phrase missing.
"Apple, (2 of Bear, Car, Dog), Ear" ------------ NO – No sets detected in scope.
"Apple, (2 of (Bear), Car, Dog), Ear" --------- NO – Sets < 2 in scope.
"Apple, (2 of (Bear), Car, (Dog)), Ear" ------ YES – Sets > 1 in scope
"Apple, (Bear), Car, (Dog), Ear" ----------------- NO – Key phrase missing.
"Apple, (2 of Bear, (Car)), (Dog)" -------------- NO – Sets < 2 in scope.
"Apple or (2 of (Bear or Car), (Dog, Ear))YES – Sets < 1 in scope.

how about this:


if test it string by string (not whole page at once, as provided by you) i think it works.
plz let me know

Thank you for your help, I truly appreciate it!
But I don’t think that your solution works, based on the results shown in the following image.

y, sorry, it works, but i see now, pasting it is not very good. lots of characters go lost
if all goes well, my regex should be there.

let me know again…

I see a regex, but I have no way of knowing if it’s your latest revision. Perhaps send a screenshot if you want to try again, so as to ensure we’re on the same page. :slight_smile:
The regex that I see in your file, doesn’t seem to be passing the tests depicted in my above file. So I’ve edited my file a bit, to try and better explain. Here’s the file and screenshot, to ensure they’re the same.
As you can see, all the strings that have YES adjacent to them ARE being matched, which is good. But some of the NOs are also being matched, which I’m trying to avoid.

Here’s the checklist:

  1. Ensure the string contains the phrase “# of”, where # represents any digit (refer to string #4).
  2. Ensure the string contains 2 of more (stuff) sets (refer to string #3).
  3. If the matched string is nested, restrict step (2) to within the nest (refer to string #9).

omg, you are correct. idk how it is editted.
but, good idea the screenshot:

lets hope that one stays where it is!

so, does it work or not?

Did it show up?

hey, why the capture groups. if i remove them the test works the same.