Rx找到匹配的括号

编程入门 行业动态 更新时间:2024-10-09 07:29:17
本文介绍了Rx找到匹配的括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何编写匹配的括号? 用于以下表达式: sin(30)+(1 + 2) 正则表达式只能找到罪(30),不是整个字符串,sin ( 30)+(1 + 2 )。"30"+(1 + 2"括号内的这个字符串没有匹配的括号。 要获得功能部分我需要正则表达式匹配括号。 MCSD .NET,SCJP,SCJWD

How can I write matching parenthesis?for the following expression.sin(30) + (1 + 2)Regex should find only sin(30) , not the whole string, sin(30) + (1 + 2) ."30) + (1 + 2" this string inside the parenthesis doesn't have matching parenthesis.To get only function part I need regular expression matching parenthesis.


MCSD .NET, SCJP, SCJWD

推荐答案

你想使用非贪婪的算子。 " \(。+?\)"应该在括号内为你匹配。 当你有嵌套的括号时,我还没有找到方法。那就是更复杂,我不相信可以使用正则表达式来处理嵌套的括号,但是我给你的是应该为此工作。 You'd want to use a non-greedy operator. "\(.+?\)" should get matches for you within parenthesis.  I haven't found a way yet when you have nested parenthesis, however.  That'd be far more complicated, and I don't believe it'd be possible to use a regular expression to handle nested parenthesis, but what I gave you should work for this.

更多推荐

Rx找到匹配的括号

本文发布于:2023-11-29 02:27:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   Rx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!