gpt4 book ai didi

regex - Notepad++:删除字符串中多个字符之后的所有内容

转载 作者:行者123 更新时间:2023-12-01 22:24:02 31 4
gpt4 key购买 nike

下面是Notepad++中每行24个字符的示例。我需要将每行字符限制为 14 个字符。

Hell, how is she today ?

我需要它看起来像下面这样:

Hell, how is

我使用了这段代码

Find what: ^(.{1,14}).*
Replace with: $1

但是,它显示“Hell, how is s”,拼写错误。

如何在 Notepad++ 中将字符数限制为每行 14 个字符并删除最后一个单词?

最佳答案

这应该适合你:

查找内容:^(.{1,14}(?<=\S)\b).*$

替换为:$1

所以对于Hell, how is she today ?输出是:Hell, how is

DEMO

^                # The beginning of the string
( # Group and capture to \1:
.{1,14} # Any character except \n (between 1 and 14 times (matching the most amount possible))
(?<=\S) # This lookbehind makes sure the last char is not a space
\b # The boundary between a word char (\w). It matches the end of a word in this case
) # End of \1
.*$ # Match any char till the end of the line

关于regex - Notepad++:删除字符串中多个字符之后的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28124538/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com