我一直在尝试自己理解正则表达式,但是我无法使字符串中的最后一个括号消失。
例如:
[The Day the Earth Stood Still]
我只能得到:
Day the Earth Stood Still]
使用以下正则表达式代码:
/(\[|\](^The ))\2/
我只是想看:
地球停转之日
非常感谢您的帮助。我已经花了3个小时试图自己解决这个问题...现在我放弃了。 :3
例如:
[The Day the Earth Stood Still]
我只能得到:
Day the Earth Stood Still]
使用以下正则表达式代码:
/(\[|\](^The ))\2/
我只是想看:
地球停转之日
非常感谢您的帮助。我已经花了3个小时试图自己解决这个问题...现在我放弃了。 :3
你可以尝试:
\[The\s(.*)]
如果你需要使此函数在'The'不存在时也能去除括号,请尝试:
(?:\[The\s|\[)(.*)]
(?:\[[Tt]he\s|\[)(.*)]
这里是一些代码,用于实现捕获文本而不包括括号和“The”:
var title = new Array();
title[0] = "[The Day the Earth Stood Still]";
title[1] = "[Independence Day]";
title[2] = "[the Day the Earth Stood Still]";
alert(title[0].match(/(?:\[[Tt]he\s|\[)(.*)]/)[1]);
alert(title[1].match(/(?:\[[Tt]he\s|\[)(.*)]/)[1]);
alert(title[2].match(/(?:\[[Tt]he\s|\[)(.*)]/)[1]);
在这里尝试一下:http://jsfiddle.net/aSwYz/
(?<=\[The\s*)[\w\s]*(?=\])