0

Simple question... I am just baffled how to write the notation.

Example: input='..."aaaa\"bbbb"...'

I need regex to grab the string ignoring nested quotations.

I guess it can start like: input=input.replace(/[^\\]"...

How can I say 'all characters until a " which is not preceded by a \' ?

Thanks!

1
  • Further question: anyone want to attempt a solution that won't break in ex. like "...\\" with a backslash at end of sentence? Double backslashes should be substituted before hand or something I guess, since no recursive regex. Commented Nov 28, 2010 at 8:51

1 Answer 1

3
"([^"\\]|\\.)*"

Inside the quotes can be (a) any character aside from a quote or backslash, or (b) any character if it's escaped with a backslash. Repeat.

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

5 Comments

Thanks, very interesting solution. Doesn't seem to catch this though "\"" "a\"" "aa\"" etc
@user202987, I guess this will match aaaa and bbbb? Do you want to match so? Or aaaa"bbbb?
You are right weakish, I want to grab the nested quotes just not terminate the string with them. From his description it seems that is what his answer should do. It seems to work for above example but not all.
When I test on "a\"a" it works properly, but "a\"" it seems to take empty string (last 2 quotes) and leave the "a\ behind.
Oooook I find there's a previous regex line on my code messing this case up sorry, will need to rewrite it in the same way. Works beautifully! Thanks :)))

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.