是否可以選擇所有單詞,即不是標籤而不是標籤內部的屬性?我已經得到了這個反作用,我知道我可以在兩個階段做到這一點,取代第一場比賽,並做出新的Javascript RegExp搜索。但事情是,我想用一種表達方式讓它工作。正則表達式 - 選擇不是標籤名稱或屬性的單詞
(<[^>]*>)|({[^>]*})
輸入:
<p>Test image captions for GitBook:</p>
<p>Second image: <img scr="./image2.png" alt="image title" title="image title">asdf</img>{caption width="300" style="height:'300px'"} </p>
<p>Sample text and first image: <img scr="./image1.png" alt="image 1" /> {caption width="300" style="height:'300px'"} for testing ok...</p>
預計輸出標記內`應該匹配的單詞:
<p>`Test` `image` `captions` `for` `GitBook`:</p>
<p>`Second` `image`: <img scr="./image2.png" alt="image title" title="image title">`asdf`</img>{caption width="300" style="height:'300px'"} </p>
<p>`Sample` `text` `and` `first` `image`: <img scr="./image1.png" alt="image 1" /> {caption width="300" style="height:'300px'"} `for` `testing` `ok`...</p>
見http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-標籤 – Ultimater
太糟糕了javascript/nodejs正則表達式不支持負面回送... – MarkokraM
雖然JavaScript支持負向預覽。您可以嘗試顛倒您正在處理的字符串,並顛倒您匹配的文字字符的順序,然後以相反的方式使用前瞻。您可能會對http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript – Ultimater