[[https://tool.oschina.net/regex/|在线测试]] === 匹配某字符串之后的内容 === [[https://stackoverflow.com/questions/10768924/match-sequence-using-regex-after-a-specified-character|外部链接]] /(?<=abc).*/ === 匹配某字符串之前的内容 === [[https://stackoverflow.com/questions/7124778/how-to-match-anything-up-until-this-sequence-of-characters-in-a-regular-expres|外部链接]] /.+?(?=abc)/ === 匹配夹在两字符串之间的内容 === /(?<=abc).*?(?=abc)/ === sed 替换夹在两字符串中间的内容 === echo 'name="LiLei"' | sed -r 's|(^.*").*("$)|\1HanMeimei\2|' # 替换到文件 sed -r 's|(^.*").*("$)|\1HanMeimei\2|' -i test.txt