RegExp问题:找到无与伦比的右括号 [英] RegExp question: Find unmatched right bracket

查看:57
本文介绍了RegExp问题:找到无与伦比的右括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有正则表达式在字符串中找到第一个不匹配的右括号

,如果有的话?例如,


"(1 *(2 + 3))))" .search(/ regexp /)== 9


提前致谢。

Is there a regular expression to find the first unmatched right bracket
in a string, if there is one? For example,

"(1*(2+3))))".search(/regexp/) == 9

Thanks in advance.

推荐答案

rk ****** @ earthlink.net 写道:
rk******@earthlink.net wrote:
是否有正则表达式来查找字符串中第一个不匹配的右括号,如果有的话?
Is there a regular expression to find the first unmatched right
bracket in a string, if there is one?




我不这么认为。我会用其他两个字符替换每对匹配的括号

,然后使用indexOf(")"):


var sText ="( 1 *(2 + 3))))" ;;

while(sText!=(sText = sText.replace(/ \(([^()] *)\)/, " _



I don''t think so. I would replace every matching pair of brackets
with two other characters and then use indexOf(")"):

var sText = "(1*(2+3))))";
while (sText != (sText = sText.replace(/\(([^()]*)\)/, "_


1_")));

alert(sText.indexOf(")"));


ciao,dhgm
1_")));
alert(sText.indexOf(")"));

ciao, dhgm


Dietmar Meier写道:
Dietmar Meier wrote:
while(sText!=(sText = sText.replace( / \(([^()] *)\)/," _
while (sText != (sText = sText.replace(/\(([^()]*)\)/, "_


这篇关于RegExp问题:找到无与伦比的右括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆