简体   繁体   English

正则表达式中的 %s+% 是什么意思?

[英]What is the meaning of %s+% in regex?

I'm trying to understand the meaning of %s+% in this solution我正在尝试理解此解决方案中%s+%的含义

Replace a set of pattern matches with corresponding replacement strings in R 用 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 %% ?我知道\s+用于匹配一个或多个空格,但是%%里面的含义是什么?

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.我已经研究了特殊的 PCRE 符号和其他东西,但没有找到任何东西。 Can anyone give me some explanation about it?谁能给我一些解释?

The function does a concatenation with a call to C function. function 与对 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根据 output 的行为,似乎 C function 是paste0的优化版本

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM