replace 相关问题

替换是搜索字符串以查找子字符串并将其替换为其他字符串的操作。

如何在 Flet 中更新完整布局

在下面的代码中,我创建了一个 Flet 应用程序,其中两个文本控件应根据按钮的点击量更新其数字。为什么这没有发生? 一点背景知识:...

回答 2 投票 0

正则表达式字符串解析:模式以 ; 开头但可以以 [;,)%&@] 结尾

我正在尝试使用正则表达式解析字符串。字符串看起来像: Stack;O&verflow;i%s;最好的! 我想将其解析为: Stack&verflow%s最好! 所以当我们看到一个 ;删除所有内容直到...

回答 1 投票 0

PHP - 替换两个特定字符后的所有文本

我正在尝试使用 PHP 对多行字符串进行搜索/替换。我需要检查每一行,如果该行包含双斜杠,则删除它及其后的所有文本,但保留下一行...

回答 4 投票 0

在最后一次出现任何白名单字符时截断字符串

我想使用正则表达式来删除最后一次出现的一些特殊符号之后的字符串。即我有绳子 你好吗 ?这个,正在测试 那么我需要这样的输出 你好,你好吗...

回答 3 投票 0

正则表达式用“et al”替换第二个逗号之后的所有内容

当某本书的作者太多时,我尝试解析一些文本(作者姓名)来替换第二个逗号之后的所有内容。 例子 : 米歇尔·加拉诺、冉阿让、米歇尔·特朗布莱……

回答 2 投票 0

preg_replace 特定域名

我使用 str_replace 将 PDF 的 URL 从 https://example.com/documents/en/whatever.PDF 重写为 https://example.com/documents/es/whatever_SPANISH.pdf 这就是我正在使用的 如果($_COOKIE['

回答 1 投票 0

如何替换 Polars DataFrame 中出现的整个字符串而不是子字符串?

我正在使用包含数千个字符串列的 Polars DataFrame,并且我正在寻找一种方法来将整个数据中字符串“0”的所有实例替换为“-1”...

回答 2 投票 0

如何使用正则表达式用逗号替换新行

如何使用正则表达式用逗号替换新行 客厅 斯堪的纳维亚语 家 房间 活的 到 客厅,斯堪的纳维亚,家,房间,客厅 我了解正则表达式,但我对正则表达式了解不多。 我打赌这是一个

回答 1 投票 0

我想用新月顺序数字的名称替换列中的字符串

我有一个名为 ID 的列的数据框,其中包含以下字符串:“10387-14_S91_L001”和“1590-13H-caso14_S76”,总共 20 个不同的 ID,它们沿着 107 重复自身

回答 1 投票 0

我需要将 <type> 节点中的文本值更改为

我从不同的 xml 文件导入。 结构示例: 1) 1-样本.xml 3 我从不同的 xml 文件导入。 结构示例: 1) 1-样本.xml <?xml version="1.0" encoding="UTF-8"?> <root> <kyero> <feed_version>3</feed_version> </kyero> <property> <type><![CDATA[Detached Villa]]></type> <town>Ciudad Quesada</town> </property> <property> <type><![CDATA[Semi Detached Villa]]></type> <town>Benijofar</town> </property> </root> 2-样本.xml <?xml version="1.0" encoding="UTF-8"?> <root> <kyero> <feed_version>3</feed_version> </kyero> <property> <type>semi-detached-villa</type> <town>Villena</town> </property> <property> <type>Semi</type> <town>Elda</town> </property> </root> 3-样本.xml <?xml version="1.0" encoding="UTF-8"?> <root> <kyero> <feed_version>3</feed_version> </kyero> <property> <type>Semi-Detached House</type> <town>Villena</town> </property> <property> <type>Semi - Detached Villa</type> <town>Elda</town> </property> </root> 我需要将节点中的文本值更改为 SemiDetached。 我正在使用 str_replace 函数。 function house_type_propertynew($type){ $type = str_replace('Semi Detached Villa', 'SemiDetached', $type); $type = str_replace('Detached Villa', 'SemiDetached', $type); $type = str_replace('Semi-Detached House', 'SemiDetached', $type); $type = str_replace('Semi', 'SemiDetached', $type); $type = str_replace('Semi-Detached House', 'SemiDetached', $type); $type = str_replace('Semi - Detached Villa', 'SemiDetached', $type); return $type;} 结果是几个值而不是“SemiDetached”: 半独立式 - 半独立式 半独立式独立式 半独立式 也就是说,文本被重复、混合、折叠不同,但没有给出所需的“半分离”结果! 我想澄清一下,在xml文件中,节点中有其他值需要更改为其他文本值,也有节点中的值不需要更改。 需要更改的示例: function house_type_propertynew($type){ $type = str_replace('Parking Space', 'garage', $type); $type = str_replace('Apartamento', 'Apartment', $type); $type = str_replace('Ground Floor', 'Apartment', $type); $type = str_replace('Flat', 'Apartment', $type); $type = str_replace('detached house', 'SemiDetached', $type); $type = str_replace('Semi', 'SemiDetached', $type); $type = str_replace('Detached Villa', 'SemiDetached', $type); $type = str_replace('Semi-detached', 'SemiDetached', $type); $type = str_replace('Semi-Detached House', 'SemiDetached', $type); $type = str_replace('semi-detached-villa', 'SemiDetached', $type); $type = str_replace('Semi - Detached Villa', 'SemiDetached', $type); $type = str_replace('Terraced house', 'Town House', $type); $type = str_replace('Townhouse', 'Town House', $type); $type = str_replace('terraced house', 'Town House', $type); $type = str_replace('House – Townhouse', 'Town House', $type); $type = str_replace('Quad Bungalow', 'Quad', $type); $type = str_replace('Quad House', 'Quad', $type); $type = str_replace('Quadplex', 'Quad', $type); $type = str_replace('Quad Villa', 'Quad', $type); $type = str_replace('Chalet', 'Villa', $type); $type = str_replace('Chalets Pareados', 'Villa', $type); $type = str_replace('Village house', 'Villa', $type); $type = str_replace('Village House', 'Villa', $type); $type = str_replace('Villa with annex', 'Villa', $type); $type = str_replace('Villas Pareados', 'Villa', $type); $type = str_replace('Finca / Country Property', 'Country Estate', $type); $type = str_replace('finca', 'Country Estate', $type); $type = str_replace('Country Property/Finca', 'Country Estate', $type); $type = str_replace('Country Property', 'Country Estate', $type); $type = str_replace('Country House', 'Country Estate', $type); $type = str_replace('Plot of Land', 'Plot', $type); $type = str_replace('Building Plot', 'Plot', $type); $type = str_replace('land', 'Plot', $type); $type = str_replace('Land', 'Plot', $type); $type = str_replace('Restoration Project', 'Plot', $type); $type = str_replace('Duplex apartment', 'Duplex', $type); $type = str_replace('Bar', 'Restaurants and Bars', $type); $type = str_replace('Bar/Restaurant', 'Restaurants and Bars', $type); $type = str_replace('Commercial Unit', 'commercial', $type); $type = str_replace('Commercial Building', 'commercial', $type); $type = str_replace('Locales Comerciales', 'commercial', $type); $type = str_replace('Business premises', 'commercial', $type); $type = str_replace('Bungalows Planta Baja', 'Bungalow', $type); $type = str_replace('Bungalows Planta Alta', 'Bungalow', $type); return $type;} 我做错了什么? 所以它用 SemiDetached 替换所有值,它不起作用! function house_type_propertynew($type){ $type = preg_replace('/<type>(.*?)<\/type>/', '<type>SemiDetached</type>', $type); return $type;} 您编写 str_replace 命令的方式,它们是累积的。因此,如果您从“半独立别墅”开始,第一个 str_replace 就会转变为“半独立别墅”。 但是,几行之后,我们搜索“Semi”并将其替换为“SemiDetached”,因此我们的字符串现在是“SemiDetachedDetached”...等等。 为了避免这种情况,您可以将所有可能的搜索作为数组放入 str_replace 的第一个参数中,并避免搜索替换字符串中的内容(即不搜索“Semi”): function house_type_propertynew($type) { return str_replace([ 'Semi Detached Villa', 'Detached Villa', 'Semi-Detached House', 'Semi - Detached Villa', ], 'SemiDetached', $type); } 或者,您可以使用 preg_replace 进行更复杂的模式匹配

回答 1 投票 0

yq 内联替换会删除文件的其余部分

我有以下yaml文件 api版本:apps/v1 种类:部署 元数据: 名称:应用程序后端 标签: 应用程序:应用程序后端 规格: 副本:1 选择器: 匹配标签: 应用程序:应用程序返回...

回答 1 投票 0

将 {{xxx}} 替换为 %s

如何将下面句子中的{{......}}替换为%s? String str="您在 {{start_time}} 与 {{provider_name}} 的预约已在 {{careCenter_name}} 取消。请致电 {{careCenter_phoneN...

回答 4 投票 0

创建在指定位置包含指定值的列表

我想创建一个给定值列表和位置列表的列表。 例如,假设值和位置的列表是 lst1 = [[a,b],[c,d]] 和 lst2=[[[1,2],[3,4]],[[1,3],[2,4]],[[1,4]...

回答 1 投票 0

将 Markdown 符号转换为 HTML 标签,除非在 <pre> 或 <code> 标签内

我正在尝试用文本块中的 HTML 标签替换特殊符号/占位符。到目前为止,它运行良好,但如果可替换实体位于...

回答 2 投票 0

将 BBCode [link='www.example.com]example[/link] 转换为 HTML <a href="www.example.com">example</a>

我的正则表达式有问题。我想翻译 BBCode 链接标签,例如: [link=www.stackoverflow.com]Stack-Overflow[/link] 转换为 HTML 链接: 堆栈溢出&...

回答 2 投票 0

将 BBCode [url] 标签转换为可点击的 HTML <a href> 链接 [重复]

我对其他 BBCode 使用 str_replace(),但我坚持使用 url 部分。 我需要转换: [url=http://maps.google.com/maps?ie=UTF-8&oe=utf-8&rls=org.mozilla:en-US:official&cli...

回答 2 投票 0

将匹配日期替换为 R 中重复行中的对应日期

在以下数据中,我想将任何值为“6/1/2020”的 GrDate 替换为同一个人(Nb)的相应 GrDate 值。 所以对于 Nb = 100,我想替换...

回答 1 投票 0

如何在Python中删除特定字符之前的所有字符?

我想删除指定字符或字符集之前的所有字符(例如): intro =“<>我是汤姆。” 现在我想在我之前删除 <> (或者更具体地说......

回答 12 投票 0

如何用新单词替换 .txt 文件中重复出现的单词的多个匹配项?

所以我有一个包含多个数据帧的 .txt 文件。它看起来类似于以下示例: $刺激 转 82289.8878539、82294.8309221、82299.3357436、82304.1822179 类别 1, 2, 1, 1 东方263、313、26...

回答 1 投票 0

使用VI搜索和替换如何替换最后两组单引号内的文本?

我有很多这样的台词: { id:22, 姓名: 'Alice', 得分: 123, 城市: '亚特兰大', 生日: '1981/12/03'}, 我想使用 VI(确切地说是 gvim)搜索并替换并清空最后两组...

回答 4 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.