replace 相关问题

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

将第一次出现的列值替换为另一个值

我有以下 2D DataFrame,我想将每列中第一次出现的值 2 替换为值 4。注意,只有列中第一次出现的值,其余 2 位于

回答 1 投票 0

从字符串中删除单字母单词(以及前导或尾随空格)

我有一个字符串,例如:Bruce A Johnson 我希望是布鲁斯·约翰逊。 如何使用 PHP 从字符串中删除单个 A? (所有只有 1 个字符的“单词”需要删除)

回答 3 投票 0

如何替换出现的管道 (|),而不替换用作分隔符的管道

在 Linux 服务器上,我有一些用竖线分隔的文件,这些文件在某些字符串列中包含竖线 (|) 字符。文件是用管道分隔的,但分隔符管道始终用双引号引起来,而管道位于...

回答 1 投票 0

C#中如何从列表中随机选择单词并用下划线隐藏它们?

我正在做一个必须显示文本的程序,每次用户按回车键时,程序都必须从单词列表中选择随机单词并用下划线隐藏它们。 我妈妈爱我,因为我...

回答 1 投票 0

根据数据帧的所有因子列的条件,用 NA 替换行的特定级别

我有一个大型数据框 df_f,跨多列具有不同级别(本例中为 5 列): c1 <- as.factor(c("NA", "1.1_mif", "NA", "NA", ...

回答 1 投票 0

Oracle - 更新字符串以仅替换最后一个字符

我在 Oracle 9i 数据库中有以下字符串: 甲、乙、丙、 当“,”是字符串中的最后一项时,我需要替换它的所有实例。我提出了以下声明,但它删除了...

回答 5 投票 0

如何在 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

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