求大佬正则匹配下面一段话里的特定字符转换成a链接。

发布于 2022-09-12 22:32:17 字数 1833 浏览 34 评论 0

ALK, anaplastic lymphoma kinase, is a receptor in the insulin receptor superfamily and is a key regulator of neuronal development (PMID: 21502284) and also promotes cell proliferation through activation of MAPK and PI3K signaling pathways (PMID: 27573755). Alk activating mutations, rearrangements, and fusions have been identified in various cancers (PMID: 22649787), including EML4-ALK in non-small cell lung cancer (PMID: 30108712, PMID: 30194140), and a number of mutations confer resistance in the context of Alk fusions (PMID: 25749034, PMID: 21948233).

转换成

ALK, anaplastic lymphoma kinase, is a receptor in the insulin receptor superfamily and is a key regulator of neuronal development (PMID: 21502284) and also promotes cell proliferation through activation of MAPK and PI3K signaling pathways (PMID: 27573755). Alk activating mutations, rearrangements, and fusions have been identified in various cancers (PMID: 22649787), including EML4-ALK in non-small cell lung cancer (PMID: 30108712, PMID: 30194140), and a number of mutations confer resistance in the context of Alk fusions (PMID: 25749034, PMID: 21948233).

自己的写法:react
image.png
这不是放在html里吗?为什么不显示a链接?而结果却是下面这样:
image.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ杯具 2022-09-19 22:32:17

这个时候是不是要说谢邀(?)

const t = s.replace(/\(PMID: (\d+)\)/g, (s, id) => `<a href="https://pubmed.ncbi.nlm.nih.gov/${id}/">${s}</a>`)
画骨成沙 2022-09-19 22:32:17
var str = `ALK, anaplastic lymphoma kinase, is a receptor in the insulin receptor superfamily and is a key regulator of neuronal development (PMID: 21502284) and also promotes cell proliferation through activation of MAPK and PI3K signaling pathways (PMID: 27573755). Alk activating mutations, rearrangements, and fusions have been identified in various cancers (PMID: 22649787), including EML4-ALK in non-small cell lung cancer (PMID: 30108712, PMID: 30194140), and a number of mutations confer resistance in the context of Alk fusions (PMID: 25749034, PMID: 21948233).`
var regone = /[\(|\)]/g
var regtwo = /PMID:\s*(\d+)/g
var n = str.replace(regone, '').replace(regtwo, (s, id) => `<a href="https://pubmed.ncbi.nlm.nih.gov/${id}/">${s}</a>`)
        document.querySelector('body').innerHTML = n

楼上的已经ok了,不过他的正则(PMID: 25749034, PMID: 21948233)这样没

有匹配出来。

点击不能跳转的原因是你的a标签必须是在html里面才可以!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文