0
votes

I wanted to select text within quotes using regex as per below scenario -

Regex should select text between the quotes. If there are nested quotes it should select all inner nested quotes instead of outer ones.

Ex 1 - Sample.text.value "The quick brown fox"

Result should be - The quick brown fox

Ex 2 - Sample.text.value "The quick brown fox" random text here one "jumps over the lazy dog" random text here two

Result should be - The quick brown fox and jumps over the lazy dog

Ex 3 - "Sample.text.value "The quick brown fox" random text here one "jumps over the lazy dog" random text here two"

Result should be - The quick brown fox and jumps over the lazy dog

I am trying this regex "([^"]*)"

This works fine in first two cases. But in third case it does not select as expected.

It selects Sample.text.value and random text here one and random text here two.

But I need The quick brown fox and jumps over the lazy dog to be selected.

Is it possible via regex ?

1
Which programming language or tool are you using?blhsing
@blhsing I am using Java.Kuldeep Singh
are you looking for: (?<=")\S[^"]+\S(?=")?Onyambu
@Onyambu Thanks. It helped to extract the part I wanted.Kuldeep Singh
did this regex work?Onyambu

1 Answers

0
votes

Check on the next regex (?m)(?!^)\"((?:(?!\").)*)\".

To try the regular expression online and get an explanation, click here.