复杂的正则表达式。 部分匹配字符串未选中

Current REGEX:

\(\_IF\_\(\%([a-zA-Z0-9_]+)\=([a-zA-Z0-9_]+)\)\{\s+(.*?)\s+(\}\)+)

Current Input:

<div class="right-side w-37">
    (_IF_(%verified=1){
        (_IF_(%post_on_profile=1){
            what is going on!!
        })
    })
</div>

Look at this demo: http://regex101.com/r/fN2kG5/#debugger

Launch the debugger if not launched already, click on the green line that says "Match 1 - ...." and go to the bottom.

You will see that at the very end of the code, the characters }) are left apart from the match. I don't know what I did wrong but I need them inside the match string. There can be multiple occurence of '})', like '})})'. so I need to add all of them inside the match string.

But how?

Thanks! :)

From the end of your regex remove this (\}\)+) and replace with below one:

(\}\)\s*)+

Here its placing an optional spaces \s* there and repeating that with +.

You could use recursion here to get all the closing }) if any:

\(\_IF\_\(\%([a-zA-Z0-9_]+)\=([a-zA-Z0-9_]+)\)\{(?:((?R))|[^{}])+\}\)

regex101 demo

Unfortunately, you cannot get all the variable/value pairs with regex alone. You could however use the above regex in a function, and pass the third captured group in recursion until you no more have a third captured group. This way, you will obtain all the variable/value pairs.