I have a String like – "Bangalore,India=Karnataka". From this String I would like to extract only the substring "Bangalore". In this case the regex can be – (.+),.*=.*. But the problem is, the String can sometimes come like only "Bangalore". Then in that case the above regex wont work. What will be the regex to get the substring "Bangalore" whatever the String be ?
I have a String like – Bangalore,India=Karnataka . From this String I would like
Share
Try this one:
Explanation:
Updated:
I thougth OP have to match
Bangalore,India=KarnatakaorBangalore=Karnatakabut as farr as I understand it isBangalore,India=KarnatakaorBangaloreso the regex is much more simpler :This will match, at the begining of the string, one or more non-comma character and capture them in group 1.