I am starting to learn go and got into a problem(challenge). I have to format text.
Input will be like: api=<http://example.com/first/api:latest|example.com/first/api:latest>;
And I want output like this:
api=example.com/first/api:latest
i.e. strip gt & lt signs, http
OR text before |
and >
sign.
Context: Slack bot. It interprets text with dot as link and sends it in <..|..>
format. If you are not clear, please feel free to comment.
I was seeing net/url
but I think that would be not of big help.
Any help, comment, resource I should see will be highly appreciated. Thanks.
评论:
titpetric:
procipher:https://play.golang.org/p/snse0sObOf
- match text between <...>
- split by |
- take second part (right of |)
- trim length by one (getting rid of >)
- replace match with the cleaned value
Should be enough as a base for whatever you're doing from here out.
titpetric:Bit generalization would be to take nearest
<
and>
from|
... case: https://play.golang.org/p/3cCTpDRWij .Anyway, thank you very much.
procipher:Easy enough fix, one character: https://play.golang.org/p/ydHwwFxOI_ (regex changes from
[^>]
to[^<>]
). There's probably edge cases abound...
Yep. Thanks. btw, good that it also works if there is
|
before or after the link stuff :)
