rajesh kakawat
rajesh kakawat

Reputation: 10896

Regexpression search for document is requires or not

I have json string. In that I want to check if any document required is true and document number is not passed.

JSON

[{"doc_name": "Birth ceritificate", "original_doc_req": true, "duplicate_doc_req": false, "doc_num": ""}..]

For example above string say that original document is required and document number is blank. so I want regular expression that should give me true.

so I want something [ regexpression ]like this

 { contain true + ""}

What I am to get only string between two curly braces

\{(.*?)\}

I can do that by looping json through javascript but I want it to be done by Reg exp

Sample json string which I am having .I have have hundred of json like this

FIDDLE

Upvotes: 0

Views: 34

Answers (2)

user1636522
user1636522

Reputation:

Is it ok now?

/true[^}]*""/

You can use it like this :

regex.test(json) // -> true or false

Upvotes: 1

xdazz
xdazz

Reputation: 160883

You should not use regex to check the string.

Instead, parse the string (by JSON.parse(str)) to an javascript array (by your case), then check the result.

Upvotes: 0

Related Questions