简体   繁体   English

查找开头括号的结尾括号,但与结尾括号完全匹配

[英]Finding ending bracket for opening bracket, but exact matching closing bracket

I don't know how to explain this without showing this javascript code, so here it is: 我不知道如何在不显示此javascript代码的情况下对此进行解释,因此它是:

syntax="{middle/point/{??/midpoint-x/(;start;)/(;end;)}:{??/midpoint-y/(;start;)/(;end;)}}";
syntax_e=syntax.replace(/\{(.*?)\}/gim,function($1){alert($1);});
alert(syntax_e);

Input: 输入:

{middle/point/{??/midpoint-x/(;start;)/(;end;)}:{??/midpoint-y/(;start;)/(;end;)}} {中间/点/ {?? /中点-X /(;启动;)/(末端)}:{?? /中点-γ/(;启动;)/(末端;)}}

Expected outputs: 预期产出:

> middle/point/{??/midpoint-x/(;start;)/(;end;)}:{??/midpoint-y/(;start;)/(;end;)}

> ??/midpoint-x/(;start;)/(;end;)

and

> ??/midpoint-y/(;start;)/(;end;)

Resulting output: 结果输出:

middle/point/{??/midpoint-x/(;start;)/(;end;) 中间/点/ {?? /中点-X /(;启动;)/(末端)

That and a few others that shouldn't be as they are. 那和其他一些不应该如此。 Where it isn't stopping at it's matching ending bracket. 它不止于匹配的结尾括号。

This is for an app where you type in commands like this, and a graphing calculator of course processes and executes each command within { and }, one after another, and when it comes to a command with more brackets/commands in it, it is supposed to evaluate it first then return the value, as specified by the $ mark which means return value. 这是针对一个应用程序,您在其中键入这样的命令,并使用一个图形计算器来当然处理并依次在{和}中执行每个命令,而其中涉及到带有更多括号/命令的命令,则是应该先对它求值,然后返回由$标记指定的值,这意味着返回值。 But without this I can't get anything done, otherwise I will have to do it a more longer and way that is not useful for people less knowledgable to computers or programming/scripting. 但是没有这个,我什么也做不了,否则我将不得不做更长的时间,而且这种方式对那些不太了解计算机或编程/脚本的人没有用。

Live example : http://jstone88.bugs3.com/desmos It will execute a few alerts with the unneeded results. 实时示例: http : //jstone88.bugs3.com/desmos它将执行一些带有不必要结果的警报。

I am sorry if I wasted time and there is already a given answer to this, it's difficult sometimes for me to get the correct wording in the search. 很抱歉,如果我浪费时间并且已经有了答案,有时我很难在搜索中得到正确的措词。

在Blog.stevenlevithan.com找到matchRecursive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM