gpt4 book ai didi

Java Regex - 正则表达式

转载 作者:行者123 更新时间:2023-12-01 11:00:29 24 4
gpt4 key购买 nike

我的正则表达式有问题。当在字符串中设置表达式时,会出现错误。

java.util.regex.PatternSyntaxException:索引 1 附近的正则表达式模式中存在语法错误:10-27 09:53:48.297 15052-15052/com.plugapps.freecommerce E/AndroidRuntime: {[/^{}\]]*David[/^{}\]]*}

我该怎么办?

最佳答案

看看这个!我想要返回数组中具有我的搜索值的对象,例如“Daventry”。

我正在使用:{[^{}\]]*Daventry[^{}\]]*}

[
{
"id": 113548,
"name": "Daventry",
"state_id": 1446,
"state_name": "Northamptonshire",
"state_code": "J1",
"country_id": 232,
"country_name": "United Kingdom",
"country_code": "GB",
"country_flag": "GB.png",
"currency_code": "GBP",
"currency_symbol": "£"
},
{
"id": 192392,
"name": "Daverdisse",
"state_id": 484,
"state_name": "Luxembourg",
"state_code": "06",
"country_id": 22,
"country_name": "Belgium\n",
"country_code": "BE",
"country_flag": "BE.png",
"currency_code": "EUR",
"currency_symbol": "€"
},
{
"id": 115981,
"name": "Davey",
"state_id": 4138,
"state_name": "Nebraska",
"state_code": "NE",
"country_id": 233,
"country_name": "United States\n",
"country_code": "US",
"country_flag": "US.png",
"currency_code": "USD",
"currency_symbol": "$"
},
{
"id": 142184,
"name": "David",
"state_id": 3350,
"state_name": "Neamt",
"state_code": "28",
"country_id": 181,
"country_name": "Romania\n",
"country_code": "RO",
"country_flag": "RO.png",
"currency_code": "RON",
"currency_symbol": "lei"
},
{
"id": 108261,
"name": "David",
"state_id": 4127,
"state_name": "Kentucky",
"state_code": "KY",
"country_id": 233,
"country_name": "United States\n",
"country_code": "US",
"country_flag": "US.png",
"currency_code": "USD",
"currency_symbol": "$"
}
]

并且仅返回:

[
{
"id": 113548,
"name": "Daventry",
"state_id": 1446,
"state_name": "Northamptonshire",
"state_code": "J1",
"country_id": 232,
"country_name": "United Kingdom",
"country_code": "GB",
"country_flag": "GB.png",
"currency_code": "GBP",
"currency_symbol": "£"
}
]

但是出现以下错误:

java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1: 10-27 09:53:48.297 15052-15052/com.plugapps.freecommerce E/AndroidRuntime: {[/^{}]]Daventry[/^{}]]}

关于Java Regex - 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33368148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com