0

I'm currently working on parsing out json objects from a string(and I'm close), but my regex just can't handle multiple objects throughout the string.

Here's my current regex:

/(\[{|\{)(?=.)(?: [^*] | (R) )*(\}]|\})/g

And here is my test string. I'm trying to capture both type of objects, {...} and [{...}].

Below is the string test string that I'm using.

Here is some json string for regex to parse [{"funarray": [12, 343, 4], "name": "John Doe", "age": 23, "_id": "ad14ab20-df9a-11e7-9ece-3b010fca83e0", "created_at": 1513124107987 }, {"name": "Jane Doe", "age": 28, "_id": "ad167fe0-df9a-11e7-9ece-3b010fca83e0", "created_at": 1513124107998 }, {"name": "John Smith", "age": 21, "_id": "ad16a6f0-df9a-11e7-9ece-3b010fca83e0", "created_at": 1513124107999 }] And heres the end of the string! But if we add another json object at the end, it shouldn't capture this middle string. {"funarray": [12, 343, 4], "name": "Greg Johnson", "age": 20, "_id": "da54a650-df9a-11217-9ece-3faebe8320", "created_at": 1513124186254 }.This string here shouldnt be captured either.

2

1 Answer 1

1

I figured it out after realizing my initial question was actually invalid regex for javascript. Here is the answer:

(\[{|\{)(?=.)(?:[^.+]|(R))*(\}]|\})(?=.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.