我有一個字符串變量,我想在id="resultcount"
元素中提取標題值。輸出應該是2
。如何使用Javascript regexp從字符串中提取標題值?
var str = '<table cellpadding=0 cellspacing=0 width="99%" id="addrResults"><tr></tr></table><span id="resultcount" title="2" style="display:none;">2</span><span style="font-size: 10pt">2 matching results. Please select your address to proceed, or refine your search.</span>';
我試過以下的正則表達式,但它不工作:
/id=\"resultcount\" title=['\"][^'\"](+['\"][^>]*)>/
引用你一些史詩:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – stefanw 2010-11-16 20:17:29