正则表达式匹配大括号里面的内容
匹配大括号里面的内容方法有两种。
方法1:
1{[^}]+}
2示例:
3var str = "aa ds sdf {asdf asdfag }";
4var str1 = str.match(/\{[^\}]+\}/)[0];
方法2:
/{[\S\s]+}/
或者 /{(.|\r\n)+}/
注:\S\s可是微软文档中对\n匹配的标准用法
示例:
1var str = "aa ds sdf {asdf asdfag }";
2var str1 = str.match(/\{[\S\s]+\}/)[0];
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/regex-brace/6078.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.