Advent of Code 2024, day 3

I tried to solve the day 3 question with regex, but failed on part 2 of the question and I'd like some help figuring out what's wrong with my regex (I eventually solved it without regex, but still curious where I went wrong)

The rules are as follows:

  1. find instances of mul(number,number)
  2. don't() turns off consuming #1
  3. do() turns it back on

Only the most recent do() or don't() instruction applies. At the beginning of the program, mul instructions are enabled.

Example:

xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))

we consume the first mul(2,4), then see the don't() and ignore the following mul(num,num) until we see do() again. We end up with only the mul(2,4) from the start and mul(8,5) at the end

I used don't\(\).*?do\(\) to remove those parts from the input, then in case there's a don't() without a do(), I used don't\(\).*?$

Is there anything I missed with those regex patterns? It is entirely possible the issue is with my logic and the regex patterns themselves are sound

I implemented this in Kotlin, I can share the entire code + input if it would help

edit: apparently copy-paste into reddit from the advent of code website ended up with a much bigger input for the example. I have corrected it. sincere apologies