Reputation: 1
I wanted to ask this as I looked and it's specific and couldn't find other threads on it.
I want to make a regex that will Capture everything that would lie between two quotations and the quotations as well surrounding.
like: "insert whatever string here (which can include " "'s)"
basically I want a regex line that would take the quotations AND everything in between them (can be anything).
So a line with quotations and anything that lies inside of it.
I can't seem to figure this out.
Upvotes: 0
Views: 185
Reputation: 7663
From the regex side of things, you could try this:
str = %q{uncaptured " captured " " /captured " /uncaptured}
str[/".*"/]
#=> "" captured " " /captured ""
For a non-regex solution, you just find the first and last index and collect the substring in between:
str[str.index('"')..str.rindex('"')]
Upvotes: 1
Reputation: 6076
I think you are just having a problem with the single and double quotes. Use this:
%q{like: "insert whatever string here (which can include " "'s)"}[/".*"/]
Upvotes: 1