I have this String (please note that I must use this as string, not converted to JSON).
String cats = "[{'_id':'abxyz','image':'http://127.0.0.1/abxyz.png','name':'Tabby Cat'},{'_id':'xyzr2','image':'http://127.0.0.1/abxr2.png','name':'Calico Cat'},{'_id':'ghjkl','image':'http://127.0.0.1/ghjkl.png','name':'Persian Cat'},{'_id':'ojr12','image':'http://127.0.0.1/ojr12.png','name':'Angora Cat'}]";
or for better readability: (there is no white space between object)
String cats =
"[{'_id':'abxyz','image':'http://127.0.0.1/abxyz.png','name':'Tabby Cat'},\
{'_id':'xyzr2','image':'http://127.0.0.1/abxr2.png','name':'Calico Cat'},\
{'_id':'ghjkl','image':'http://127.0.0.1/ghjkl.png','name':'Persian Cat'},\
{'_id':'ojr12','image':'http://127.0.0.1/ojr12.png','name':'Angora Cat'}]";
I want to extract the Calico Cat object using regex. I tried to use
String pattern = "{\'_id\':\'xyzr2\'.*}"
Unfortunately, the selection expands from Calico Cat to Angora Cat:
{'_id':'xyzr2','image':'http://127.0.0.1/abxr2.png','name':'Calico Cat'},\
{'_id':'ghjkl','image':'http://127.0.0.1/ghjkl.png','name':'Persian Cat'},\
{'_id':'ojr12','image':'http://127.0.0.1/ojr12.png','name':'Angora Cat'}
What kind of regex pattern I need to isolate only the Calico Cat? Expected result:
{'_id':'xyzr2','image':'http://127.0.0.1/abxr2.png','name':'Calico Cat'}