gpt4 book ai didi

javascript - 正则表达式 - 选择不是标签名称或属性的单词

转载 作者:行者123 更新时间:2023-11-27 23:36:55 24 4
gpt4 key购买 nike

是否可以选择所有非标签且不在标签内的单词作为属性?我已经得到了这个逆工作,我知道我可以分两个阶段完成这个工作,替换第一个匹配项并进行新的 Javascript RegExp 搜索。但问题是我想让它用一种表达方式工作。

http://regexr.com/3cb6g

(<[^>]*>)|({[^>]*})

输入:

<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>

最佳答案

我的问题可能不太清楚,因为答案是使用 JavaScript 代码来处理匹配。我的目的是仅用简单的表达来找到解决方案。我终于找到了这个满足我需求的表达方式:

((?!([^<]+)?>)([\w]+)(?!([^\{]+)?\})([\w]+))

http://regexr.com/3cb6j

关于javascript - 正则表达式 - 选择不是标签名称或属性的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34059249/

24 4 0
文章推荐: javascript - 如何在MVC4的UI中使用jQuery创建DataTable?
文章推荐: javascript -
文章推荐: javascript - 在 Javascript 中设置