unknown_boundaries
unknown_boundaries

Reputation: 1600

Regex to get text between first and last inverted commas

The text is -"http://en.wikipedia.org/wiki/"The_Above_Ground_Sound"_of_Jake_Holmes":hey. I need regex to get http://en.wikipedia.org/wiki/"The_Above_Ground_Sound"_of_Jake_Holmes. I tried to write \"(.*?)\" but failed since the inverted commas are nested. I need to get last occurrence of " at last ending part.

I think I need negative look ahead solution but not sure.

Upvotes: 1

Views: 2191

Answers (2)

Giuseppe Ricupero
Giuseppe Ricupero

Reputation: 6272

Actually what the OP needs based on his request is:

(?<=").*(?=") 
# match only the contents without the external double quotes "..." ->
# http://en.wikipedia.org/wiki/"The_Above_Ground_Sound"_of_Jake_Holmes

Online demo

Upvotes: 3

Mardrey
Mardrey

Reputation: 76

"(.*)"

This grabs everything between two double quotation marks and it grabs in a greedy fashion. This means that it will try and match as much text as possible between the two quotation marks.

Upvotes: 6

Related Questions