jQuery 正则表达式获取两个字符之间的所有内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19836706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Regex get all content between two characters
提问by Paul Adam Harrison
I need to get content between symbols [ and ] even there are other same characters i need to take content between first [ and last ]. In jquery useing regex. Thanks Advance
我需要在符号 [ 和 ] 之间获取内容,即使还有其他相同的字符我需要在第一个 [ 和最后一个 ] 之间获取内容。在 jquery 中使用正则表达式。感谢提前
回答by Denys Séguret
No need for jQuery, use standard Javascript :
不需要 jQuery,使用标准 Javascript :
var extract = str.match(/\[(.*)\]/).pop();
If your delimiters are { and }, change it to
如果您的分隔符是 { 和 },请将其更改为
var extract = str.match(/{(.*)}/).pop();
回答by OGHaza
How about
怎么样
yourStringVariable.match(/\[(.*)\]/)[1]