0

I'm pretty unfamiliar with regex. I would like to run a regex search against lines like:

if env == production
    #define DBHOST "serv1.ns.com"
    #define DBSLAVEHOST "serv2.ns.com"
    #define DBHOSTAUX "serv3.ns.com"
endif

I have the following which finds the lines I want: ^(?=.*\\bDB)(?=.*HOST).*, but I'm not positive how to match and return whatever the last word in the line is -- i.e., serv1.ns.com, serv2.ns.com, serv3.ns.com

1
  • will the desired output be in double quotes in all instances? Commented May 6, 2015 at 19:45

1 Answer 1

1

You can use this regex:

^\s*#define\s+[A-Z]*DB[A-Z]*HOST[A-Z]*\s+"?(.*?)"?$

Sample

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks - I want to make sure it contains both DB and HOST though.. so this is almost what I want right?
Does this actually return the result serv1.ns.com, etc.? Which part of your regex is the value portion?
@MrDuk the first capturing group is the value, you can see it on the sample site on the right

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.