截取地址

---------------------------------------------------------------------------------------------地址
--起步
update z_beijing_all_web33 set ent_address=substr(web_text,instr(web_text,'地址',1)-10,50)
where is_yellp is null and web_text like '%地址%' and ent_address is null

--截取地址第1 步
update z_beijing_all_web33 set ent_address=substr(ent_address,instr(ent_address,'地址','1'),length(ent_address))
where ent_address is not null
--截取地址第2 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'邮箱','1')-1)
where ent_address is not null and ent_address like '%邮箱%'
--截取地址第3 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'邮编','1')-1)
where ent_address is not null and ent_address like '%邮编%'
--截取地址第4 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'座机','1')-1)
where ent_address is not null and ent_address like '%座机%'
--截取地址第5 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'手机','1')-1)
where ent_address is not null and ent_address like '%手机%'
--截取地址第6 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'联系电话','1')-1)
where ent_address is not null and ent_address like '%联系电话%'
--截取地址第7 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'电话:','1')-1)
where ent_address is not null and ent_address like '%电话:%'
--截取地址第8 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'查看地图','1')-1)
where ent_address is not null and ent_address like '%查看地图%'
--截取地址第9 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'地图','1')-1)
where ent_address is not null and ent_address like '%地图%'
--截取地址第10 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'邮政编码','1')-1)
where ent_address is not null and ent_address like '%邮政编码%'
--截取地址第11 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'Copyrigh','1')-1)
where ent_address is not null and ent_address like '%Copyrigh%'
--截取地址第12 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'特色','1')-1)
where ent_address is not null and ent_address like '%特色%'
--截取地址第13 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'技术支持','1')-1)
where ent_address is not null and ent_address like '%技术支持%'
--截取地址第14 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'网址','1')-1)
where ent_address is not null and ent_address like '%网址%'
--截取地址第15 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'附近的商户','1')-1)
where ent_address is not null and ent_address like '%附近的商户%'
--截取地址第16 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'主营分类','1')-1)
where ent_address is not null and ent_address like '%主营分类%'
--截取地址第17 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'联系人','1')-1)
where ent_address is not null and ent_address like '%联系人%'
--截取地址第18 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'咨询热线','1')-1)
where ent_address is not null and ent_address like '%咨询热线%'
--截取地址第19 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'当前位置','1')-1)
where ent_address is not null and ent_address like '%当前位置%'
--截取地址第20 步
update z_beijing_all_web33 set ent_address=substr(ent_address,0, instr(ent_address,'当前位置','1')-1)
where ent_address is not null and ent_address like '%当前位置%'
--截取地址第21 步
update z_beijing_all_web33 a set a.is_yellp ='2'
where ent_address is not null and ent_address not like '%北京%' and ent_address like '%省%' and ent_address like '%市%'


--

update z_beijing_all_web33 set ent_address = replace(ent_address,'?','') where ent_address like '%?%'
<think>好的,用户想了解如何在JavaScript中截取图片地址中的图片名称。首先,我需要确定用户的具体需求。他们可能有一个图片的URL,比如"http://example.com/images/pic.jpg",想要从中提取出"pic.jpg"或者不带扩展名的"pic"部分。 接下来,我得考虑不同的URL结构情况。例如,有的URL可能包含查询参数,像"pic.jpg?version=123",这时候直接按斜杠分割可能不够,还要处理问号后的参数。另外,可能有的文件名中有多个点,比如"image.min.jpg",这时候可能需要保留整个文件名,包括中间的点。 常用的方法是通过字符串分割来处理。首先,使用split('/')将URL按斜杠分割成数组,然后取最后一个元素,这样可以得到文件名部分。但之后还要处理可能的查询参数,可以用split('?')[0]来去除参数部分。如果用户想要不带扩展名的名字,可以再用split('.')[0],但需要注意多个点的情况,这样可能只会保留第一个点之前的部分,比如"image.min.jpg"会被截断为"image"。 另外,可能需要考虑使用正则表达式来更灵活地匹配文件名部分。正则表达式可以更精确地提取所需的字符串,尤其是在复杂的情况下。例如,使用/\/([^\/?]+)[^\/]*$/.exec(url)这样的正则式,可以匹配最后一个斜杠后的内容,直到遇到问号或结束,这样可以同时处理查询参数和锚点。 还要提醒用户注意不同情况下的处理方式,比如URL是否编码过,是否需要解码,或者是否有哈希值(如#anchor)。这些都可能影响最终的提取结果,需要根据实际需求进行调整。 最后,应该给出几个不同的方法示例,让用户可以根据自己的具体情况选择合适的方法。比如,基础方法适用于简单情况,处理参数和扩展名的方法适用于更复杂的情况,正则表达式方法则更为灵活和强大。同时,代码示例要简洁明了,方便用户直接使用和测试。</think>在 JavaScript 中截取图片地址中的图片名称,可以通过字符串处理方法或正则表达式实现。以下是几种常见方法: --- ### 1. 基础方法:通过 `split` 分割字符串 假设图片地址为 `http://example.com/images/pic.jpg`: ```javascript const url = "http://example.com/images/pic.jpg"; const fileName = url.split('/').pop(); // 获取最后一个斜杠后的内容 console.log(fileName); // 输出 "pic.jpg" ``` --- ### 2. 处理带参数的地址(如 `pic.jpg?version=123`) ```javascript const url = "http://example.com/images/pic.jpg?version=123"; // 先分割路径和参数,再取文件名 const fileNameWithParams = url.split('/').pop(); const pureFileName = fileNameWithParams.split('?')[0]; console.log(pureFileName); // 输出 "pic.jpg" ``` --- ### 3. 提取不带扩展名的名称 ```javascript const url = "http://example.com/images/pic.jpg"; const fileNameWithExtension = url.split('/').pop(); const fileNameWithoutExtension = fileNameWithExtension.split('.')[0]; console.log(fileNameWithoutExtension); // 输出 "pic" ``` --- ### 4. 使用正则表达式(推荐) 更健壮的方式,兼容复杂路径和参数: ```javascript const url = "http://example.com/images/pic.jpg?version=123#section"; const match = url.match(/\/([^\/?]+)[^\/]*$/); const fileName = match ? match[1] : ''; console.log(fileName); // 输出 "pic.jpg" ``` --- ### 5. 完整函数封装 ```javascript function getImageName(url) { // 处理 URL 编码(如空格被转为 %20) const decodedUrl = decodeURIComponent(url); // 匹配文件名部分 const regex = /\/([^\/?]+)(\?|$)/; const match = decodedUrl.match(regex); return match ? match[1] : ''; } // 示例 console.log(getImageName("http://example.com/photo%201.jpg")); // 输出 "photo 1.jpg" ``` --- ### 常见场景说明 - **带哈希或参数**:如 `pic.jpg#anchor` 或 `pic.jpg?width=200`,上述方法均可兼容。 - **多层路径**:如 `http://example.com/2023/images/pic.png`,仍会正确提取 `pic.png`。 - **无扩展名**:如 `http://example.com/file`,会直接返回 `file`。 根据实际需求选择最适合的方法即可!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值