Description
You will need to modify the βwhat I'm looking forβ block to contain all the same leading spaces that exist in the target data.
Your text search will need to be inserted into this expression between the \Q ... \E tags. Then the expression will find the name of the template for the selected block of text, the name will be placed in Capture Group 1.
^template:\s*(\S*).*?(?=^)(?:^\s+(?:(?!^).)*)*?^\Q - type: cfgstore hosts: - {name: ymscfg-02.ops.bf1.yahoo.com, farm: east} - {name: ymscfg-02.ops.gq1.yahoo.com, farm: west} - type: aggregator hosts: - {name: ymsagg-08.ops.bf1.yahoo.com, farm: east} - {name: ymsagg-10.ops.gq1.yahoo.com, farm: west} - type: metricsdb hosts: - {name: ymsdb-11.ops.bf1.yahoo.com, farm: east} - {name: ymsdb-11.ops.gq1.yahoo.com, farm: west}\E
Input text
template: perm_subcluster copy_cluster: yms_cfg_ref allocations: - type: cfgstore hosts: - {name: ymscfg-02.ops.bf1.yahoo.com, farm: east} - {name: ymscfg-02.ops.gq1.yahoo.com, farm: west} - type: aggregator hosts: - {name: ymsagg-08.ops.bf1.yahoo.com, farm: east} - {name: ymsagg-10.ops.gq1.yahoo.com, farm: west} - type: metricsdb hosts: - {name: ymsdb-11.ops.bf1.yahoo.com, farm: east} - {name: ymsdb-11.ops.gq1.yahoo.com, farm: west} template: Not_me copy_cluster: yms_cfg_ref allocations: - type: cfgstore hosts: - {name: Fail_ymscfg-02.ops.bf1.yahoo.com, farm: east} - {name: Fail_ymscfg-02.ops.gq1.yahoo.com, farm: west} - type: aggregator hosts: - {name: ymsagg-08.ops.bf1.yahoo.com, farm: east} - {name: ymsagg-10.ops.gq1.yahoo.com, farm: west} - type: metricsdb hosts: - {name: ymsdb-11.ops.bf1.yahoo.com, farm: east} - {name: ymsdb-11.ops.gq1.yahoo.com, farm: west}
Matches
[0] => template: perm_subcluster copy_cluster: yms_cfg_ref allocations: - type: cfgstore hosts: - {name: ymscfg-02.ops.bf1.yahoo.com, farm: east} - {name: ymscfg-02.ops.gq1.yahoo.com, farm: west} - type: aggregator hosts: - {name: ymsagg-08.ops.bf1.yahoo.com, farm: east} - {name: ymsagg-10.ops.gq1.yahoo.com, farm: west} - type: metricsdb hosts: - {name: ymsdb-11.ops.bf1.yahoo.com, farm: east} - {name: ymsdb-11.ops.gq1.yahoo.com, farm: west} [1] => perm_subcluster
source share