<p>I am starting to learn go and got into a problem(challenge). I have to format text.</p>
<p>Input will be like: <code>api=<http://example.com/first/api:latest|example.com/first/api:latest></code></p>
<p>And I want output like this:</p>
<p><code>api=example.com/first/api:latest</code></p>
<p>i.e. strip gt & lt signs, <code>http</code> OR text before <code>|</code> and <code>></code> sign. </p>
<p>Context: Slack bot. It interprets text with dot as link and sends it in <code><..|..></code> format. If you are not clear, please feel free to comment.</p>
<p>I was seeing <code>net/url</code> but I think that would be not of big help.</p>
<p>Any help, comment, resource I should see will be highly appreciated. Thanks.</p>
<hr/>**评论:**<br/><br/>titpetric: <pre><p><a href="https://play.golang.org/p/snse0sObOf" rel="nofollow">https://play.golang.org/p/snse0sObOf</a></p>
<ol>
<li>match text between <...></li>
<li>split by |</li>
<li>take second part (right of |)</li>
<li>trim length by one (getting rid of >)</li>
<li>replace match with the cleaned value</li>
</ol>
<p>Should be enough as a base for whatever you're doing from here out.</p></pre>procipher: <pre><p>Bit generalization would be to take nearest <code><</code> and <code>></code> from <code>|</code> ... case: <a href="https://play.golang.org/p/3cCTpDRWij" rel="nofollow">https://play.golang.org/p/3cCTpDRWij</a> . </p>
<p>Anyway, thank you very much.</p></pre>titpetric: <pre><p>Easy enough fix, one character: <a href="https://play.golang.org/p/ydHwwFxOI_" rel="nofollow">https://play.golang.org/p/ydHwwFxOI_</a> (regex changes from <code>[^>]</code> to <code>[^<>]</code>). There's probably edge cases abound...</p></pre>procipher: <pre><p>Yep. Thanks. btw, good that it also works if there is <code>|</code> before or after the link stuff :)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传