gpt4 book ai didi

regex - 在两个字符串之间替换文本

转载 作者:行者123 更新时间:2023-12-02 08:30:31 25 4
gpt4 key购买 nike

我有一个地址列表,通常为以下类型:

1000 Currie AV Apt: Minneapolis MN 55403

1843 Polk ST NE Apt: b

1801 3 AV S Apt: 203 Minneapolis MN 55404

2900 Thomas AV S Apt: 1618 MPLS MN 55416

8409 Elliott AV S Apt: Bloomington MN 55420


我是新来的正则表达式。
我想用空白替换 Apt:和所有文本,直到第一个大写字母为止。
现在,我正在尝试的代码如下:
generate address_home = regexr(address_home1, "(Apt:).*?([A-Z])", " ")

最佳答案

正则表达式:

Apt:[^A-Z\n]*

用单个空格替换匹配的字符。

DEMO

我认为您的代码应该是,
gen address_home = regexr(address_home1, "Apt:[^A-Z\n]*", " ")


gen address_home = regexr(address_home1, "Apt:[^A-Z\\n]*", " ")

不知道是否需要再次转义反斜杠。

关于regex - 在两个字符串之间替换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27407760/

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