javascript - 如何在 Google Cloud Compute node.js getVMs 中使用正则表达式进行过滤

标签 javascript node.js google-cloud-platform google-compute-engine

在 Node JS 的 Google 云计算库中,如何在 getVMs 方法中使用带有 options.filter 的正则表达式进行过滤?

文档:https://googlecloudplatform.github.io/google-cloud-node/#/docs/compute/0.7.1/compute?method=getVMs

我下面的尝试返回一个空数组,并且文档中没有明确的示例(还!)。我的目标是获得一个以“prefix”作为名称开头的实例。

共有 101 个实例,这是第 101 个。

compute.getVMs({
    maxResults: 100,
    filter: 'name eq ^prefix'
});

Search filter in the format of {name} {comparison} {filterString}. name: the name of the field to compare comparison: the comparison operator, eq (equal) or ne (not equal) filterString: the string to filter to. For string fields, this can be a regular expression.

最佳答案

您的模式末尾缺少“.$”。基本上,您需要指定您想要“匹配以“前缀”开头的字符串,然后在“前缀”之后跟随任意数量的字符,直到整个字符串的末尾”。您可以抑制“整个字符串的结尾”特殊字符 ($),但不能抑制“匹配任意数量的字符”特殊字符 (.)。这是一个工作示例:

const Compute = require('@google-cloud/compute');
const gce = new Compute({
  projectId: 'your-project-id-here'
});

gce.getVMs({
    maxResults: 100,
    filter: 'name eq ^prefix.*'
}, function(err, vms) {
  console.log(vms);
});

关于javascript - 如何在 Google Cloud Compute node.js getVMs 中使用正则表达式进行过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081916/

相关文章:

javascript - 在 WordPress 上寻找用于照片的 Nivo Slider

node.js - AWS Lambda/APIG - 在新 Sequelize 的新 PostgresDialect 的新 ConnectionManager 处出错

javascript - 使用 grunt 观察并重新编译单个模板

python - Google 函数超出内存

javascript - 如何在 Firebase 中检索多个 key ?

javascript - 带有 require 的父指令 Controller 上的 Angular 监视

javascript - 有没有办法使用 jquery 将替代文本添加到 img 标签?

html - 如何使用 ng-repeat angularjs 打印 html 中的数据

python - Google 管理的 VM 模块卡在重启循环中

google-cloud-platform - 如何更新数据流不兼容的管道而不丢失数据?