简体   繁体   English

正则表达式在两个天使大括号之间查找值文本<<值>>j

[英]Regex to find value between two Angel braces text << value >>j

I am looking to get value SPR2 from below string我希望从下面的字符串中获取值 SPR2

var myString = "BUILDING - WITH DELETION OF EXCLUSION (d) & (e)<<SPR2>>"

please help请帮忙

In the future, please identify what solutions you have tried before asking for assistance on Stack Overflow.将来,在寻求 Stack Overflow 帮助之前,请确定您尝试过哪些解决方案。

The expression you are looking for is (<{2}\\w+>{2}) , as demonstrated here .你正在寻找的表达是(<{2}\\w+>{2})这表现在这里

You would then take a substring of each match and remove the << and >> characters.然后,您将获取每个匹配项的子字符串并删除 << 和 >> 字符。

Start to end, the solution would be as follows:从头到尾,解决方法如下:

 var str = 'BUILDING - WITH DELETION OF EXCLUSION (d) & (e)<<SPR2>>'; var regex = /<{2}(\\w+)>{2}/g; var matches = str.match(regex); matches.forEach(function(match) { console.log(match.substring(match.indexOf('<<') + 2, match.lastIndexOf('>>'))); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM