删除R中两种字符串模式之间的字母 [英] Remove the letters between two patterns of strings in R

查看:31
本文介绍了删除R中两种字符串模式之间的字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除 R 中两个特定模式之间的字母?

How can I remove the letters between two specific patterns in R?

例如

a= "a#g abcdefgtdkfef_jpg>pple"

我想删除 #gjpg>

a1="apple"

我试图在 stringr 中找到一些函数,但我找不到

I tried to find some function in stringr but I couldn't

推荐答案

添加到之前的回复中,如果您使用的字符串看起来像 "a#g abcdefgtdkfef_jpg>pple ; #__something_else___jpg>",其中一些方法将使用像 "#.*jpg>" 这样的表达式来细分整个字符串,结果您将得到一个空字符串.为了避免这种情况,您可以使用 R 正则表达式 "#[^jpg>]+jpg>" 这将允许您更有选择地匹配模式.

Adding to the previous replies, if you work with a string that looks like "a#g abcdefgtdkfef_jpg>pple ; #__something_else___jpg>", some of these methods will sub the whole string with an expression like "#.*jpg>", and you will get an empty string as a result. To avoid that, you can use R regex "#[^jpg>]+jpg>" that will allow you to match the pattern more selectively.

这篇关于删除R中两种字符串模式之间的字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆