Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用正则表达式替换以下字符串:
No. 1.
和:
<a name='1'></a>No. 1.
其中“1”可以是一位或两位数(例如 1、2、26、99)
假设所有数字都以相同的方式声明,这很容易用 JavaScript 完成:
foo.replace(/No\. (\d+)\./, "<a name='$1'></a>No. $1.");
使用 GNU sed:
echo "No. 1." | sed "s#No\. \(\[0-9\]\+\)\.#<a name='\1'></a>\0#"