gpt4 book ai didi

regex - 重新调整代码以提高可读性

转载 作者:IT王子 更新时间:2023-10-29 01:43:06 25 4
gpt4 key购买 nike

我有一些代码看起来像

Id string // uniq bid req id provided by the exchange
Fields []interface{} // array of field objects
User interface{} // user obj
Device interface{}

我知道 align-regexp 函数,我用它来对齐我的注释。这会输出类似的东西

Id string            // uniq bid req id provided by the exchange
Fields []interface{} // array of field objects
User interface{} // user obj
Device interface{}

但是,我也希望类型能够正确对齐。我试图弄清楚如何使用 align-regexp 来完成此操作。不幸的是,我缺乏正则表达式技能。

我希望输出看起来像

Id     string        // uniq bid req id provided by the exchange
Fields []interface{} // array of field objects
User interface{} // user obj
Device interface{}

我不介意这是两个独立的函数调用,因为我可以编写一个可以封装它们的函数。

此外,我不关心解决方案是否最终使用 align-regexp。到目前为止,这就是我一直在使用的东西。

最佳答案

它可能比你想象的要简单。

你的类型总是一个词吗?然后你可以使用一个空格作为第一个正则表达式,然后在 // 上对齐。它确实适用于这个例子:)

关于regex - 重新调整代码以提高可读性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25935646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com