在Javascript中与正则表达式递归匹配 [英] Recursive matching with regular expressions in Javascript

查看:290
本文介绍了在Javascript中与正则表达式递归匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例字符串: $$ {a},{s $$ {d} $$} $$

我想首先匹配 $$ {d} $$ 并将其替换为一些文本,以便字符串变为 $$ {a} ,{sd} $$ ,然后 $$ {a},{sd} $$ 将匹配。

I'd like to match $${d}$$ first and replace it some text so the string would become $${a},{sd}$$, then $${a},{sd}$$ will be matched.

推荐答案

令人讨厌的是,Javascript没有提供PCRE递归参数(?R),所以很远从容易处理嵌套问题。但是可以这样做。

Annoyingly, Javascript does not provide the PCRE recursive parameter (?R), so it is far from easy to deal with the nested issue. It can be done however.

我不会重现代码,但如果你看看 Steve Levithan的博客,他有一些关于这个主题的好文章。他应该这样做,他可能是JS中RegExp的主要权威。他写了 XRegExp ,它取代了大多数缺少的PCRE位,甚至还有匹配递归插件!

I won't reproduce code, but if you check out Steve Levithan's blog, he has some good articles on the subject. He should do, he is probably the leading authority on RegExp in JS. He wrote XRegExp, which replaces most of the PCRE bits that are missing, there is even a Match Recursive plugin!

这篇关于在Javascript中与正则表达式递归匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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