1

I have below data

May 18 22:15:04 172.24.11.74 "abc","5","0",........

I want to capture only abc it could be anything (abc,bcd, aaa or it can be empty ), so I want to ignore May 18 22:15:04 172.24.11.74 . Also after Immediate match it should stop .So in simple terms I want to match everything between first "". Please help me to understand how I can achieve it . I tried following

(?<=")([\w\s]+)(?=")

It works fine only if first double quotes have some value . But when it is blank it moves further and capture next value in the double quotes . For example for below message it captures 5.

May 18 22:15:04 172.24.11.74 "","5","0"

I hope I am clear with my requirement .

1 Answer 1

1

I think you were almost there.

If you make the group in the middle optional by adding a ? behind it, it matches even if there's nothing between the double quotes:

(?<=")([\w\s]+)?(?=")

Alternatively you can match the middle part * times instead of + times which means one or more times and by this does not match if the part is empty:

(?<=")([\w\s]*)(?=")

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

Comments

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.