您的位置:首页 > 其它

正则表达式匹配以指定字符串开头并且以指定字符串结尾

2018-01-31 14:03 561 查看
假如有如下json文件:

{
"Result": [
{
"country": "TW",
"mcc": "466",
"chatUrl": "https://motorola-global-chn.custhelp.com/"
},
{
"country": "AU",
"mcc": "505",
"chatUrl": "https://motorola-global-en-aus.custhelp.com/"
},
{
"country": "NZ",
"mcc": "530",
"chatUrl": "https://motorola-global-en-aus.custhelp.com/"
},
{
"country": "AT",
"mcc": "232",
"chatUrl": "https://motorola-global-en-roe.custhelp.com/"
},
{
"country": "BE",
"mcc": "206",
"chatUrl": "https://motorola-global-en-roe.custhelp.com/"
},

...我们需要将其中的chatUrl全部替换成
https://motorola-global-portal--dev2.custhelp.com/
我们可以在idea中或者文件编辑器如notepad中完成这项操作。使用字符串匹配并且开启使用正则表达式匹配的模式,我们使用匹配字符串开头和结尾的方式来完成字符串的替换。那么我们需要匹配所有:
以https://开头的并且以.com/结尾的字符串匹配上述模式的正则表达式是: https://.+.com/也就是,我们使用下面的方式: 开头字符串.+.结尾字符串的模式来完成匹配。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: