Roland
Roland

Reputation: 344

What is the meaning of %s+% in regex?

I'm trying to understand the meaning of %s+% in this solution

Replace a set of pattern matches with corresponding replacement strings in R

The important part of the code is this

xxx_replace_xxx_pcre(string, "\\b" %s+% patterns %s+% "\\b", replacements)

I know that \s+ is used to match one or more spaces, but what is the meaning inside %% ?

I tried to use the code without it, because I just want to match inside word boundaries, but it gives an error

xxx_replace_xxx_pcre(string, "\\b" patterns "\\b", replacements)

I already researched about special PCRE symbols and other things, but didn't find anything. Can anyone give me some explanation about it?

Upvotes: 1

Views: 648

Answers (1)

akrun
akrun

Reputation: 887851

The function does a concatenation with a call to C function. We can check the source code from console by backquoting the operator

library(stringi)
`%s+%`
function (e1, e2) 
{
.Call(C_stri_join2, e1, e2)
}

Based on the behavior of the output, it seems that the C function is an optimized version of paste0

paste0("\\b", patterns, "\\b")

Upvotes: 1

Related Questions