Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find strings in strings

I have the following string:

here "is 'a' \"string\" that" does contain a 'lot of "weird"' stuff "i" to 'find'

I want to extract is 'a' \"string\" that, lot of "weird", i and find.

Any ideas? Thanks!

like image 422
Aron Woost Avatar asked Dec 17 '25 17:12

Aron Woost


1 Answers

This negative lookbehind based regex should work for you:

/(["']).*?(?<!\\)\1/g

Live Demo: http://www.rubular.com/r/X3etmgKFNH

Regex without support of lookbehind e.g. Javascript

/(['"])(?:\1|.*?[^\\]\1)/g

Live Demo: http://www.rubular.com/r/SQyEYIPS4l

like image 145
anubhava Avatar answered Dec 19 '25 18:12

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!