如何使用正则表达式从以下文本中获取数字4968?
"category_path":["XXX1430","XXX109026","XXX3120","XXX4968","XXX377357"]
非常感谢!
答案 0 :(得分:0)
尝试正则表达式:category_path":\[(?:"[X]+\d+",){3}"[X]+\K\d+
答案 1 :(得分:0)
如果您想使用正则表达式,则可以在(\d+)
组中捕获4968。
"category_path":\["XXX\d+"(?:,"XXX\d+"){2},"XXX(\d+)"(?:,"XXX\d+")*\]
解释
"category_path":\[
按字面意思匹配"XXX\d+"
匹配没有昏迷的XXX数字模式(?:,"XXX\d+"){2}
用逗号2次重复XXX数字模式"XXX(\d+)"
匹配"XXX
并捕获组(\d+)
中的一个或多个数字,并匹配"
(?:,"XXX\d+")*\]
匹配模式零次或多次以及结束]