正则表达式中替换a链接href内容为#
时间: 2024-05-03 11:20:55 浏览: 10
可以使用以下正则表达式替换a链接href内容:
```python
import re
# 原始字符串
text = '这是一个<a href="http://www.example.com">链接</a>。'
# 替换a链接href内容
new_text = re.sub(r'<a href=".*?">', '<a href="https://www.newurl.com">', text)
print(new_text)
# 输出: 这是一个<a href="https://www.newurl.com">链接</a>。
```
该正则表达式会匹配所有以`<a href="`开头的a链接,然后用`<a href="https://www.newurl.com">`替换它们的href内容。