我想使用正则表达式来替换此文本:
[Button size="Big" color="#000"] test [/Button]
到Button,我使用了这个网站http://www.freeformatter.com/regex-tester.html但没有进行替换。
正则表达式\[Button([^\]]*)\[/Button],它给我的结果String is same as before replace!是什么错误?
我想使用正则表达式来替换此文本:
[Button size="Big" color="#000"] test [/Button]
到Button,我使用了这个网站http://www.freeformatter.com/regex-tester.html但没有进行替换。
正则表达式\[Button([^\]]*)\[/Button],它给我的结果String is same as before replace!是什么错误?
您的([^\]]*)正则表达式部分将在]第一个标签关闭之前停止匹配。因此,您没有匹配字符串的模式 -"] test "此后。
将您的正则表达式修改为:
\[Button([^\]]*][^\[]*)\[/Button]
试试这个,它匹配正确,也匹配内部。
\[Button([^\]]*)\](.*?)\[/Button\]
的正则表达式
\[Button.*\]
并且替换字符串Button应该足够了。