Skip to content

Commit 264c2ea

Browse files
committed
feat: improve regex pattern of select content
1 parent d294b70 commit 264c2ea

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

jsonpath/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author : zhangxianbing
33
Date : 2020-12-27 09:22:14
44
LastEditors : zhangxianbing
5-
LastEditTime : 2021-01-06 10:22:43
5+
LastEditTime : 2021-01-13 13:29:48
66
Description : JSONPath
77
"""
88
__version__ = "1.0.1"
@@ -60,7 +60,7 @@ class JSONPath:
6060

6161
# operators
6262
REP_SLICE_CONTENT = re.compile(r"^(-?\d*)?:(-?\d*)?(:-?\d*)?$")
63-
REP_SELECT_CONTENT = re.compile(r"^([\w.]+)(,[\w.]+)+$")
63+
REP_SELECT_CONTENT = re.compile(r"^([\w.']+)(, ?[\w.']+)+$")
6464
REP_FILTER_CONTENT = re.compile(
6565
r"@\.(.*?)(?=<=|>=|==|!=|>|<| in| not| is)|len\(@\.(.*?)\)"
6666
)
@@ -267,7 +267,7 @@ def _trace(self, obj, i: int, path):
267267
if __name__ == "__main__":
268268
with open("test/data/2.json", "rb") as f:
269269
d = json.load(f)
270-
D = JSONPath("$.book[*].(title)").parse(d, "VALUE")
270+
D = JSONPath("$[bicycle, scores]").parse(d, "VALUE")
271271
print(D)
272272
for v in D:
273273
print(v)

0 commit comments

Comments
 (0)