正则表达式匹配以指定字符串开头并且以指定字符串结尾
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://开头的并且以.com/结尾的字符串匹配上述模式的正则表达式是: https://.+.com/也就是,我们使用下面的方式: 开头字符串.+.结尾字符串的模式来完成匹配。
{
"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/也就是,我们使用下面的方式: 开头字符串.+.结尾字符串的模式来完成匹配。
相关文章推荐
- 匹配指定字符开头,但不包含该字符,已指定字符结尾的字符串
- 对python 匹配字符串开头和结尾的方法详解
- php正则匹配以“abc”开头且不能以“xyz”结尾的字符串
- 判断是否以指定的字符串开头或结尾
- 去除字符串开头结尾的指定字符串
- C#自己编写的一个函数 可以删除字符串中指定开头和结尾中间的字符串
- C#自己编写的一个函数 可以删除字符串中指定开头和结尾中间的字符串
- Python-字符串开头或结尾匹配
- PHP正则表达式匹配自定义开头结尾之前字符串
- iOS开发之判断字符串是否为指定字符串开头或结尾
- 轻松python文本专题-字符串开头或者结尾匹配
- Python: 字符串开头或结尾匹配str.startswith(),str.endswith()
- NSString:创建,长度,取字符,是否以某字符串开头,结尾, 查找指定字符串的范围,截取,拼接,替换,比较,替换,数值转换,大小写转换
- 轻松python文本专题-字符串开头或者结尾匹配
- python 字符串开头或结尾匹配
- Java正则式匹配开头结尾字符串
- 轻松python文本专题-字符串开头或者结尾匹配
- python 匹配字符串开头和结尾
- php 正则取字符串中间 去指定字符串开头 指定字符串结尾
- 将字符串中开头和结尾空格去掉,并且中间空格仅仅保留一个