字符串的屬性:我需要一個正則表達式匹配以下字符串
{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)閱讀此處 –