字符串的属性:我需要一个正则表达式匹配以下字符串
{title id="fsfdsfsdf" link1="http://google.com" link1_title="Some link"}
什么属性值,我需要:
fsfdsfsdf, http://google.com, Some link
我需要他们可能是在捕获组()
正则表达式实际上是我的弱点,所以感谢任何人提出了一个方法来做到这一点,或者一些进一步的资源,最终可以帮助我解决这个问题。
字符串的属性:我需要一个正则表达式匹配以下字符串
{title id="fsfdsfsdf" link1="http://google.com" link1_title="Some link"}
什么属性值,我需要:
fsfdsfsdf, http://google.com, Some link
我需要他们可能是在捕获组()
正则表达式实际上是我的弱点,所以感谢任何人提出了一个方法来做到这一点,或者一些进一步的资源,最终可以帮助我解决这个问题。
你可以做这样的事情:
(\w+)(?==)
编辑
因为它的属性值,而不是你想要的键。然后,你可以这样做:
="((?:\\"|[^"])*?)"
var input = "{title id=\"fsfdsfsdf\" link1=\"http://google.com\" link1_title=\"Some link\"}";
const re = /="((?:\\"|[^"])*?)"/g;
match = re.exec(input);
while (match != null) {
console.log(match[1]);
match = re.exec(input);
}
,输出:
fsfdsfsdf
http://google.com
Some link
请分享你尝试过的代码。 –
...和一些正确的数据。这是一个字符串? –
由于本网站的格式,您可能最好的服务方式是通过在线RegEx教程以及StackOverflow上的[RegEx文档](http://stackoverflow.com/documentation/regex/topics)阅读此处 –