Java正则表达式:如何替换方括号内的所有字符? [英] Java regex: How to replace all character inside a bracket?
本文介绍了Java正则表达式:如何替换方括号内的所有字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何替换:
((90+1)%(100-4)) + ((90+1)%(100-4/(6-4))) - (var1%(var2%var3(var4-var5)))
使用
XYZ((90+1),(100-4)) + XYZ((90+1),100-4/(6-4)) - XYZ(var1,XYZ(var2,var3(var4-var5)))
使用正则表达式?
谢谢, J
推荐答案
对于正则表达式来说,这看起来确实不是一件好事.看来您可能想写一个快速的递归下降解析器.如果我对您的理解正确,是否要用函数名称XYZ替换中缀运算符%?
this doesn't really look like a very good job for a regex. It looks like you might want to write a quick recursive descent parser instead. If I understand you correctly, you want to replace the infix operator % with a function name XYZ?
因此(expression%expression)变为XYZ(expression,expression)
So (expression % expression) becomes XYZ(expression, expression)
这似乎是学习的好资源: http: //www.cs.uky.edu/~lewis/essays/compilers/rec-des.html
This looks like a good resource to study: http://www.cs.uky.edu/~lewis/essays/compilers/rec-des.html
这篇关于Java正则表达式:如何替换方括号内的所有字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文