簡體   English   中英

使用 html 標簽搜索 html 文本

[英]Search html text with html tag

我正在嘗試搜索一些可以使用或不使用 html 標簽進行搜索的文本。 已經嘗試過(?!([^<]+)?>) ,它正在處理 html 標簽之外的內容。

正則表達式 - (simple html)(?!([^<]+)?>)

Html - This is simple html text <span class='simple'>simple html</span> text simple <p>html</p>

simple <p>html</p>內容不起作用。

請注意,我避免使用class='simple'

使用:/< /<\\/?.*?>/g和replace,你可以/<\\/?.*?>/g所有的HTML 標簽,並簡單地搜索剩余的文本。

 let regex = /<\\/?.*?>/g, html = `This is simple html text <span class='simple'>simple html</span> text simple <p>html</p>`, string = html.replace(regex, ""); console.log(`Stripped HTML: ${string}`) let find = "simple html", found = string.search(find); console.log(`\\n$ String "${find}" found at char ${found}`)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM