Closed memborsky closed 4 years ago
Use re.search() to check if the value being compared is contained within the filter field.
re.search()
>>> from jsonpath_ng.ext import parse >>> >>> simple_dict = { ... "phone_numbers": [ ... { ... "type" : "iPhone", ... "number": "0123-4567-8888" ... }, ... { ... "type" : "home", ... "number": "0123-4567-8910" ... }, ... { ... "type" : "home", ... "number": "1098-7654-3210" ... } ... ] ... } >>> >>> expression = parse('$.phone_numbers[?(@.type =~ "^hom")]') >>> >>> [x.value for x in expression.find(simple_dict)] [{'type': 'home', 'number': '0123-4567-8910'}, {'type': 'home', 'number': '1098-7654-3210'}] >>> >>> expression = parse('$.phone_numbers[?(@.number =~ "[0-9]{4}-4567-[0-9]{4}")]') >>> >>> [x.value for x in expression.find(simple_dict)] [{'type': 'iPhone', 'number': '0123-4567-8888'}, {'type': 'home', 'number': '0123-4567-8910'}]
Coverage remained the same at 0.0% when pulling 7ff235a198ef1bc61ed7846bf621aaad70528a9d on memborsky:add-regular-expression-contains-support into d4b8b87407a298a48e5229be9b9fb517fb539b2f on h2non:master.
Use
re.search()
to check if the value being compared is contained within the filter field.