[R] Using regex to truncate repeating characters

Karl josip.2000 at gmail.com
Wed Nov 11 10:02:07 CET 2015


Hi all,

I'm trying to learn how to use regex inside R. I'm far from an expert when
it comes to this, but google is my friend when it comes to finding suitable
pieces of syntax to start building from. For example, this post seems to do
what I want:

http://stackoverflow.com/questions/12258622/regular-expression-to-check-for-repeating-characters
However, how do I implement this in R? gsub()?
For example, with Perl-style regex, are there syntax modifications that
need to be done before it will work with R?

My task is that I want to truncate/limit repeated characters to 3. If I
have the string:
"Looooorem ipsum dolor sit ammmmmmet, consectetur adipiscing eliiiiiiiit"

I want to truncate it to:
"Looorem ipsum dolor sit ammmet, consectetur adipiscing eliiit"

Thank you!

BR,
Josip

	[[alternative HTML version deleted]]



More information about the R-help mailing list