我想从描述字符串中过滤掉标签,并将它们变成锚标签。我无法返回标签的值。
我的输入是:
a = "this is a sample #tag and the string is having a #second tag too"
我的输出应该是:
a = "this is a sample <a href="/tags/tag">#tag</a> and the string is having a <a href="/tags/second">#second</a> tag too"
到目前为止,我能够做一些小事情,但我无法获得最终输出。这种模式:
a.gsub(/#\S+/i, "<a href='/tags/\0'>\0</a>")
返回:
"this is a sample <a href='/tags/\u0000'>\u0000</a> and the string is having a <a href='/tags/\u0000'>\u0000</a> tag too"
我需要做些什么不同的事情?