其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

利用sublime text的正则表达式解决问题

GG网络技术分享 2025-03-18 16:15 0


问题描述:

小说里的章节用 数字、 来划分,
如何用sublime text将这些 数字、 替换成 第 数字 章

网友观点:

远程看看吧

import re
strs=""
with open("2.txt","r",encoding="utf-8") as fp:

txt=fp.readline()

while txt:

tlist=re.findall("\\d+、",txt)

if tlist:

temp=tlist[0].replace("、","")

# print(temp)

txt=txt.replace(temp+"、","第"+temp+"章 ")

print(txt)

strs=strs+txt

txt = fp.readline()

with open("1.txt","a",encoding="utf-8") as f:
f.write(strs)

import re

sdf="你好34 你好 345"

print(re.findall("\\d+、",sdf))

for it in re.findall("\\d+、",sdf):

temp=it.replace("、","")

sdf=sdf.replace(it,"第"+temp+"章")

print(sdf)

print(sdf.replace("\\d+、","第1章"))

前端实用正则表达式&小技巧,一股脑全丢给你

不用看懂,收藏就完了,以后你肯定会用到的。
今天带来的是前端开发中经常碰到的数字问题,解决方式有些过于粗暴,未来还会不断美化更新。

充分利用JavaScript自带原生方法解决问题

前端页面和数据处理虽然看起来简单,但是一个优秀的前端工程师对于细节的把控也是至关重要的,如何合理处理业务也体现前端工程师对性能优化的功力

获取数组最大值和最小值

  • 利用sort排序方法
    • 针对数组进行排序,数组第一个和最后一个就是最大值和最小值

标签:

提交需求或反馈

Demand feedback