As a beginner with regex i believe im about to ask something too simple but ill ask anyway hope it won’t bother you helping me..
Lets say i have a text like “hello ‘cool1’ word! ‘cool2′”
and i want to get the first quote’s text (which is ‘cool1’ without the ‘)
what should be my pattern? and when using matcher, how do i guarantee it will remain the first quote and not the second?
(please suggest a solution only with regex.. )
Use this regular expression:
Use as follows: (ideone)
Or this if you know that there are no new-line characters in your quoted string:
It will find the first quoted string first because it starts seaching from left to right. If you ask it for the next match it will give you the second quoted string.