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
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...@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
Thanks so much Arun! It's the second case.
Being able to extract is really powerful too. Thank you for sharing that as
well!
Sent from my iPad
On Nov 4, 2012, at 12:00 AM, arun kirshna [via R]
ml-node+s789695n4648372...@n4.nabble.com wrote:
HI,
I am not sure how you want your output.
On Jan 21, 2012, at 23:04 , Sarah Goslee wrote:
+ is a metacharacter, and must be escaped:
X - one + two
gsub(\\+, plus, X)
[1] one plus two
The help for gsub() tells you to read ?regexp - that's where
the details of regular expressions as implemented in R are
explained.
...and it
I am trying to replace + in a string with another character
I am getting odd results using sub and gsub
X-one + two
gsub(+,plus,X)
[1] plusoplusnpluseplus plus+plus plustpluswplusoplus
sub(+,plus,X)
[1] plusone + two
X-one ~ two
it seems to work fine with other characters:
sub(~,plus,X)
Two ways:
i) (If you are not using full regular expressions) Set the fixed = TRUE option.
ii) Escape it.
E.g.,
gsub(\\+, plus, X)
gsub(+, plus, X, fixed = TRUE)
Read up on ?regexp for an explanation of what's going on.
Michael
On Sat, Jan 21, 2012 at 2:46 PM, Nevil Amos nevil.a...@gmail.com
+ is a metacharacter, and must be escaped:
X - one + two
gsub(\\+, plus, X)
[1] one plus two
The help for gsub() tells you to read ?regexp - that's where
the details of regular expressions as implemented in R are
explained.
Sarah
On Sat, Jan 21, 2012 at 2:46 PM, Nevil Amos
7 matches
Mail list logo