小编Ale*_*. b的帖子

Golang:使用Regex提取数据

我正在尝试提取内部的任何数据${}.

例如,从该字符串中提取的数据应该是abc.

git commit -m '${abc}'
Run Code Online (Sandbox Code Playgroud)

这是实际的代码:

re := regexp.MustCompile("${*}")
match := re.FindStringSubmatch(command)
Run Code Online (Sandbox Code Playgroud)

但这不起作用,任何想法?

regex string algorithm go

15
推荐指数
1
解决办法
2万
查看次数

Golang:在文件中查找字符串并显示行号

read, err := ioutil.ReadFile(path)
if err != nil {
    return err
}

if strings.Contains(string(read), "STRING") {
    // display line number?
    // what if many occurrences of the string
    // how to display for each the line number?
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试搜索特定字符串的文件并显示字符串所在的行号.

string algorithm loops go

7
推荐指数
1
解决办法
9574
查看次数

Golang:用它的参数执行命令

我正在尝试使用go执行命令.

executableCommand := strings.Split("git commit -m 'hello world'", " ")
executeCommand(executableCommand[0], executableCommand[1:]...)
cmd := exec.Command(command, args...)
Run Code Online (Sandbox Code Playgroud)

但这就是我得到的

error: pathspec 'world"' did not match any file(s) known to git.
exit status 1
Run Code Online (Sandbox Code Playgroud)

这是因为-m获得'hello的,而不是'hello world'因为在命令行中使用分裂" ".

有什么想让它发挥作用吗?

git command-line command go

7
推荐指数
1
解决办法
2508
查看次数

通过范围进行彻底搜索

我有一个模型Task,其范围名为done. ATask属于 aProject且属于 a User

我需要按用户已完成的项目来过滤用户task

simple_form_for @q do |form|
  form.input :tasks_done_project_id, collection: Project.ordered
Run Code Online (Sandbox Code Playgroud)

但使用“_done”不起作用。

我想到了一个掠夺者:

  ransacker :done do |parent|
    parent.done.table[:id]
  end
Run Code Online (Sandbox Code Playgroud)

但也不起作用。任何想法?

ruby sql ruby-on-rails simple-form ransack

1
推荐指数
1
解决办法
4412
查看次数

标签 统计

go ×3

algorithm ×2

string ×2

command ×1

command-line ×1

git ×1

loops ×1

ransack ×1

regex ×1

ruby ×1

ruby-on-rails ×1

simple-form ×1

sql ×1