Reputation: 665
I'm trying to setup a regex pattern match that will match 'hello'
twice in 'hello'blah blah blah 'hello'
but that will match the full string 'hello''hello'
and the full string 'hello''hello'
as well as the full string 'hello'.'hello'
.
To put it simply, I want to start a match when there is a single quote, and continue the match until I encounter another single quote, unless there is another single quote immediately after it or if there is a .'
after it, in which case I want to continue matching until I encounter a single quote that doesn't match those conditions.
This is what I have to match values between single quotes currently:
\'[^\']*\'
I already read the solution here: How to replace single quote to two single quotes, but do nothing if two single quotes are next to each other in perl but it doesn't quite fit what I'm looking for and can't get it to match the in-between stuff.
Upvotes: 0
Views: 48
Reputation: 147286
You can use this regex:
('[^']+'(?:\.?'[^']+')*)
It looks for a set of characters enclosed in single quotes, followed optionally by some number of sets of characters enclosed in single quotes, possibly preceded by a period.
Upvotes: 1
Reputation: 667
'.*?'(\.?'.*?')*
If I understand your need correctly, it's easy to construct the above regex.
Upvotes: 0