【问题标题】:How to grab block of text using regular expression (PowerShell/C#) [duplicate]如何使用正则表达式(PowerShell/C#)获取文本块 [重复]
【发布时间】:2018-06-12 11:13:53
【问题描述】:
resource "aws_instance" "launch-ec2-servers"
{
    ami = "${var.ec2_ami}"
    instance_type = "${var.instance_type}"
    key_name = "${var.key_name}"
    vpc_security_group_ids = ["${var.security_group}"]
    subnet_id = "${var.subnet_id}"
    count= "${var.count}"

    root_block_device
    {
        volume_size = "${var.root_volume_size}"
        volume_type = "${var.root_volume_type}"
    }

    ebs_block_device
    {
        device_name = "${var.ebs_device_name}"
        snapshot_id = "${var.ebs_snapshot_id}"
        volume_type = "${var.ebs_volume_type}"
    }

    tags
    {
        Name = "${var.app_name}"
    }
}

嘿,

我正在尝试使用 C#/PowerShell/ASP.Net 中的正则表达式获取 ebs_block_device 块部分。

到目前为止,我尝试将此作为我的正则表达式: (ebs_block_device)(?s)(.[^}]+.)

代码中我感兴趣的块部分是:

 ebs_block_device
    {
       device_name = "${var.ebs_device_name}"
       snapshot_id = "${var.ebs_snapshot_id}"
       volume_type = "${var.ebs_volume_type}"
    }

你能帮我正确地抓住大括号之间的那段文字吗?

【问题讨论】:

标签: c# asp.net regex powershell


【解决方案1】:

试试这个正则表达式:

(ebs_block_device)(\s+)(\{[\s\S]*?\}(?!"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多