My data strings can be in this format
1.
{"name":"Lokesh","accountNumber":"3044444444","city":"New York"}
"{\"name\":\"Lokesh\",\"accountNumber\":\"3044444444\",\"city\":\"New York\"}"
"\"{\\\"name\\\":\\\"Lokesh\\\",\\\"accountNumber\\\":\\\"3044444444\\\",\\\"city\\\":\\\"New York\\\"}\""
Basically, a JSON object that can be stringified any number of times or it can be similar looking string for example
"hello"="world"
I have written regex as
/\\*".*account.*\\*":\\*"(.*?)\\*".*/g
But it matches New YorK
But I want to match the first element i.e. 3044444444. How can I achieve this?
>Solution :
Use: \\*".*account[^,]*\\*":\\*"((.*?)\\*)".*
see: https://regex101.com/r/vb2rx4/1
Then only thing changed is that i replaced . by [^,]. A . will match anything, and [^,] will match anything but a comma.