java - 需要正则表达式来匹配两个单词,因为它们之间可能有任意数量的空格或其他字符
问题描述
假设我想匹配短语“Johnny Appleseed”,我们得到以下字符串:
<p>Johnny random blah stuff</p>
<p>more random stuff Appleseed blah blue bleh</p>
我希望能够匹配 Johnny 和 Appleseed 以便将这些单词包装在标签中,我该怎么做?
预期输出:
<p><span>Johnny</span> random blah stuff</p>
<p>more random stuff <span>Appleseed</span> blah blue bleh</p>
感谢所有建议!
注意:基本上我想要的是此页面自动使用示例字符串中的单词 Johnny 和 Appleseed 执行的操作(它使 Johhnny 和 Appleseed 的颜色与其他文本不同)
解决方案
决定使用 Jsoup 来解析我的 HTML 而不是使用正则表达式。感谢时间!
推荐阅读
- webpack - 在插件处理之前让 Webpacks file_loader 在 css 文件中读取和散列 url
- java - 自定义 Spring Boot AutoConfiguration 模块上的 IntelliJ 属性文件检测
- r - 如何将两个双层地块放在一起?
- javascript - 如何在 HTML 脚本中包含 node_module?(顺便说一句,使用 webpack)
- linux - VSCode 终端未在 Linux (POP_OS 20.10) 中打开
- javascript - 如何使用 jquery 选择和更改文本
- r - 混合列顺序,DBI::dbWriteTable 在 R 中用于 BigQuery
- sql - postgres 按月按时间顺序排列
- python - 使用 requests.json() 返回一个列表,而不是 JSON
- oracle - TRUNCATE TABLE 后,如何恢复数据?