简体   繁体   中英

How to write regex to match a key in yaml file?

I have a yaml which looks like this..! Sonar by default providing sonar-yaml-plugin with some templates which accepts regex as input to verify particular key is present or not in .yml file.

I want regex to match entire key logging:file

 server:
   port: 8989
 logging:
    file: ./sample1.txt
    path: ./log

I have tried using (logging)(?s:.*?)(file) but its not validating when I use it in sonar-plugin.

I'm not so sure what you may want to match, but maybe this regex might help you to do so or design your desired expression:

^(logging:|\s+file:)(.+)

在此输入图像描述

  • This expression has a left boundary on start ^ .
  • Your two words connected with an OR ( | )
  • Then, matches everything after that using .+
  • You can also add additional boundaries to it, however if you could add some real samples to your question, it would be easier to answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM