As your regexp gets complicated, it can get difficult to debug if you run into issues. Building your regexp step by step from scratch and testing against input strings will go a long way in correcting the problem. To aid in such a process, you could use various online tools.
rubular is an online Ruby regular expression editor (based on Ruby 2.5.7) to visually test your regexp. You need to add your regexp, input string and optional modifiers. Matching portions will be highlighted.
The below image is a screenshot from this link — rubular:
The below image is a screenshot from this link — debuggex:
The below image is a screenshot from this link — regexcrossword: tutorial puzzle 5
This chapter briefly presented three tools that help you with understanding and interactively solving/debugging regular expressions. Syntax and features can vary, sometimes significantly, between various tools and programming languages. So, you will have to be careful if the tool doesn't support the flavor you are using.