我正在尝试在 bash 脚本中使用 sed 替换某些 HTML 内容。出于某种原因,我没有得到正确的结果,因为它没有替换任何东西,主要是正则表达式部分
我要替换的 HTML
<h3 class="indicate-hover css-5fzt5q">For the Most Complex Heroines Animation
<h3 class="indicate-hover css-1pvrrwb">The Psychology Behind Sibling
到
head For the Most Complex Heroines Animation
head The Psychology Behind Sibling
我用过
sed -e 's/<h3 class="indicate-hover css-([a-b0-9]+)">/head/g'
主要是 ([a-b0-9]) 这部分执行失败,我一定是漏掉了什么,我想更具体一点,我有 "<p class="summary-class css-1azn4ub">How many words can"
我想将其替换为“tail”并拥有更多其他标签。正则表达式部分让我很痛苦
最佳答案
使用sed
$ sed 's/.*-[[:alnum:]]\+">/head /' input_file
输出
head For the Most Complex Heroines Animation
head The Psychology Behind Sibling
关于linux - 使用 sed 和正则表达式替换 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72805436/