[R] Replacing a string

R. Michael Weylandt michael.weylandt at gmail.com
Sun Nov 4 09:31:28 CET 2012


You want to read the ?regexp page and try

gsub("^http://.*\\.com$", "WEBSITE", <filename>)

Michael

On Sun, Nov 4, 2012 at 4:09 AM, Allie818 <alice.ly at gmail.com> wrote:
> Hi,
>
> I have what I hope is a simple text processing question in R.
>
> I want to replace every instance of http:\\XXX.com with "WEBSITE"
>
> When I try
> sub('(^http://)(.com$)', 'WEBSITE', <filename>);,
> it only substitutes http:// and .com so it looks like
> WEBSITEXXXWEBSITE
>
> How do I get it to match the pattern
> "http:// . . . . .com" and substitute the whole phrase?
>
> Thanks in advance!
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Replacing-a-string-tp4648368.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list