如何使用正则表达式从下面的文本中得到数字4968?
"category_path":["XXX1430","XXX109026","XXX3120","XXX4968","XXX377357"]
非常感谢!
oo7oh9g91#
如果你想使用正则表达式,你可以在一个组中捕获4968 (\d+) . "category_path":\["XXX\d+"(?:,"XXX\d+"){2},"XXX(\d+)"(?:,"XXX\d+")*\] 解释 "category_path":\[ 逐字匹配 "XXX\d+" 匹配数字模式而不昏迷 (?:,"XXX\d+"){2} 用逗号重复数字模式2次 "XXX(\d+)" 匹配 "XXX 捕捉一组中的一个或多个数字 (\d+) 匹配一个" (?:,"XXX\d+")*\] 将图案匹配零次或多次,然后结束 ]
(\d+)
"category_path":\["XXX\d+"(?:,"XXX\d+"){2},"XXX(\d+)"(?:,"XXX\d+")*\]
"category_path":\[
"XXX\d+"
(?:,"XXX\d+"){2}
"XXX(\d+)"
"XXX
(?:,"XXX\d+")*\]
]
mzaanser2#
尝试正则表达式: category_path":\[(?:"[X]+\d+",){3}"[X]+\K\d+ 演示
category_path":\[(?:"[X]+\d+",){3}"[X]+\K\d+
2条答案
按热度按时间oo7oh9g91#
如果你想使用正则表达式,你可以在一个组中捕获4968
(\d+)
."category_path":\["XXX\d+"(?:,"XXX\d+"){2},"XXX(\d+)"(?:,"XXX\d+")*\]
解释"category_path":\[
逐字匹配"XXX\d+"
匹配数字模式而不昏迷(?:,"XXX\d+"){2}
用逗号重复数字模式2次"XXX(\d+)"
匹配"XXX
捕捉一组中的一个或多个数字(\d+)
匹配一个"
(?:,"XXX\d+")*\]
将图案匹配零次或多次,然后结束]
mzaanser2#
尝试正则表达式:
category_path":\[(?:"[X]+\d+",){3}"[X]+\K\d+
演示