当前位置: 首页 > news >正文

长沙营销型网站建设汕头百度seo公司

长沙营销型网站建设,汕头百度seo公司,门户网站建设方案 模板,湖州网站建设服务标准的正则表达式是什么样的 Node.js(JavaScript) 在正则表达式中,斜杠(/)用来表示正则表达式的开始和结束。在JavaScript中,正则表达式可以使用斜杠包裹起来,以表示这是一个正则表达式的字面量。 在Node.js中&…

标准的正则表达式是什么样的

Node.js(JavaScript)

在正则表达式中,斜杠(/)用来表示正则表达式的开始和结束。在JavaScript中,正则表达式可以使用斜杠包裹起来,以表示这是一个正则表达式的字面量。

在Node.js中,可以使用正则表达式的test()方法来检查一个字符串是否匹配某个模式。以下是一个示例代码,演示了如何使用正则表达式匹配以1开头,后面跟着两个数字的字符串:

const str = '123';
const regex = /^1\d{2}$/;if (regex.test(str)) {console.log('匹配成功');
} else {console.log('匹配失败');
}

在上面的示例中,^1\d{2}$是一个正则表达式,它的含义是:

^:匹配字符串的开头
1:匹配字符1
\d{2}:匹配两个数字(\d表示任意数字,{2}表示匹配两次)
$:匹配字符串的结尾

因此,该正则表达式可以匹配以1开头,后面跟着两个数字的字符串。在示例中,str的值为123,它符合这个模式,所以输出结果为匹配成功。

Java

private void RegTest2() {String content ="abc$(abc(1.23(";//匹配(String regStr = "\\d{2}";
//        String regStr = "\\.";Pattern pattern = Pattern.compile(regStr);Matcher matcher = pattern.matcher(content);while (matcher.find()){Log.i(TAG,"match:" + matcher.group(0));}}
2023-08-11 17:49:18.021 27898-29062/cn.jj.reg I/JJWorld.MainActivity: match:23

结论

不同语言正则表达式有区别,缺乏统一的正则标准。

ASCII码表

java读取文件assets中ini文件时,转义符消失的问题

java读取文件时,分为了三步。

第一步通过inputStream获取输入流。

如果将读取到的数据依次打印的话,可以看到是读取到了转移字符的

Properties properties = IniPropertiesReadUtils.loadFileFromAssetsNew(this, "jjapm1.ini");
     //读取Assets目录下的配置文件public static Properties loadFileFromAssetsNew(Context context, String filePath) {if (null == context || null == filePath || filePath.length() == 0)return null;InputStream assetFileIS = null;InputStreamReader assetFileISReader = null;Properties properties = new Properties();int readData = 0;try {assetFileIS = context.getResources().getAssets().open(filePath);while ((readData = assetFileIS.read())!= -1){Log.i(TAG,"read:" + (char)readData);}} catch (IOException e) {e.printStackTrace();properties = null;} finally {try {if (null != assetFileIS) {assetFileIS.close();}if (null != assetFileISReader) {assetFileISReader.close();}} catch (IOException e) {e.printStackTrace();}}return properties;}

在这里插入图片描述

2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:c
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:l
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:a
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:s
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:s
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:R
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:u
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:l
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:e
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read: 
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:=
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read: 
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:ä
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:¸
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:­
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:{
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:\
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:d
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:\
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:d
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:"
2023-08-12 10:05:26.258 27428-27460/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read:}

上面打印的控制信息不管,可见是打印出来了classRule = 中{\d\d"}的,只不过中文是乱码。

第二步 通过InputStreamReader获取输入字符流,处理乱码问题

//读取Assets目录下的配置文件public static Properties loadFileFromAssetsNew(Context context, String filePath) {if (null == context || null == filePath || filePath.length() == 0)return null;InputStream assetFileIS = null;InputStreamReader assetFileISReader = null;Properties properties = new Properties();int readData = 0;try {assetFileIS = context.getResources().getAssets().open(filePath);
//            while ((readData = assetFileIS.read())!= -1){
//                Log.i(TAG,"read:" + (char)readData);
//            }assetFileISReader = new InputStreamReader(assetFileIS, "UTF-8");while ((readData = assetFileISReader.read())!= -1){Log.i(TAG,"read11:" + (char)readData);}} catch (IOException e) {e.printStackTrace();properties = null;} finally {try {if (null != assetFileIS) {assetFileIS.close();}if (null != assetFileISReader) {assetFileISReader.close();}} catch (IOException e) {e.printStackTrace();}}return properties;}
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:c
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:l
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:a
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:s
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:s
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:R
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:u
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:l
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:e
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11: 
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:=
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11: 
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:{
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:\
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:d
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:\
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:d
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:"
2023-08-12 10:06:52.827 27565-27600/cn.jj.reg I/JJWorld.IniPropertiesReadUtils: read11:}

转义符依然是存在的,classRule = 中{\d\d"}

第三步 properties.load(assetFileISReader)对转义符进行了特殊处理,导致转义符失效

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

JSONObject对转义符的处理

    private void jsonRegTest() throws JSONException {String jsonStr = "{key:\"va\\lue\"}";// JSONObject对\的处理JSONObject jsonObject = new JSONObject(jsonStr);Log.i(TAG, "jsonRegTest:" + jsonObject.toString());}

在这里插入图片描述

    public JSONObject(@NonNull String json) throws JSONException {this(new JSONTokener(json));}

new JSONObject会创建一个JSONTokener。JSONTokener保留设置进来的字符串。

    public JSONTokener(String in) {// consume an optional byte order mark (BOM) if it existsif (in != null && in.startsWith("\ufeff")) {in = in.substring(1);}this.in = in;}

JSONObject(String)核心代码

    public JSONObject(@NonNull JSONTokener readFrom) throws JSONException {/** Getting the parser to populate this could get tricky. Instead, just* parse to temporary JSONObject and then steal the data from that.*/Object object = readFrom.nextValue();if (object instanceof JSONObject) {this.nameValuePairs = ((JSONObject) object).nameValuePairs;} else {throw JSON.typeMismatch(object, "JSONObject");}}
http://www.yidumall.com/news/30711.html

相关文章:

  • c 做网站开发sem竞价课程
  • 个人备案网站可以做论坛吗百度排名点击软件
  • 企业网站开发计划书it培训机构
  • 安徽建设工程造价信息网seo整站优化多少钱
  • wordpress 仪表盘裁剪图片免费seo视频教程
  • 做全景图二维码的网站百度网站官网入口网址
  • 做网站批发利润怎么样北京百度竞价托管公司
  • 江西省宜春市建设局网站河南网站建设哪里好
  • 阿里云可以做几个网站自动的网站设计制作
  • dede网站怎么更换模板2345纯净版推广包
  • b站视频未能成功转码国外免费舆情网站有哪些软件
  • 电子商务 独立网站制作网络游戏推广员是做什么的
  • 旗舰店的网站怎么做优化大师win10下载
  • 企业网站备案需要什么资料数字营销成功案例
  • 重庆 做网站淘宝运营
  • 免费做字体的网站批量查询指数
  • 钓鱼网站模板制作新人做外贸怎么找国外客户
  • 内网网站建设龙岗网站推广
  • 大连做网站的企业可以免费网络推广网站
  • 做网站主机要选好seo小白入门教学
  • 字牌标识公司网站网站编号 6019关键词优化搜索排名
  • 西安北郊网络公司搜索引擎seo如何优化
  • 我和宠物做朋友教案小精灵网站合肥网
  • 做电商网站电商公司win优化大师
  • 建设一个网站可以做什么搜狗收录查询
  • 制作化妆品网站标题优化
  • 昆明网站建设 网络服务镇江百度seo
  • 泰康人寿网站如何做计划领取免费发布推广的平台有哪些
  • 如何购买域名建网站给公司做网站的公司
  • 公司网站客户案例优化什么建立生育支持政策体系