扫码关注官方订阅号
取出类似http://examle.com/xxx/yyy368/pichdjejjdhe9.jpghttp://examle.com/xxx/yyy245/pichdjejjdhe9.png最后的数字9,数字固定在文件名最后
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
使用正则表达式
var str = "http://examle.com/xxx/yyy368/pichdjejjdhe9.jpg"; var reg = /http:\/\/\w+\.com\/\w+\/\w+\/[a-zA-Z]+(\d)\.\w+/; reg.exec(str)[1];
var url ="http://examle.com/xxx/yyy368/pichdjejjdhe9.jpg"; console.log(url.match(/\d(?=\.)/)[0]);
能取你那个9
String imgUrl = "http://examle.com/xxx/yyy245/pichdjejjdhe9.png"; String fileName = imgUrl.substring(imgUrl.lastIndexOf("/") + 1,imgUrl.lastIndexOf(".")); String pattern = "\\d+"; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(fileName); int start = 0; int end = 0; while(m.find()){ start = m.start(); end = m.end(); } int num = Integer.parseInt(fileName.substring(start, end)); System.out.println(num);
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用正则表达式
能取你那个9