在正则表达式中有没有办法在 PCRE 语法中转义整个文本区域中的特殊字符?
例如。 hey+Im+A+Single+Word+Including+The+Pluses+And.Dots
通常情况下,以匹配正则表达式,我将不得不逃离每一个确切的字符串+
,并.
与/
S IN上面的字符串。这意味着如果字符串是一个变量,则必须寻找特殊字符并手动转义它们。通过告诉正则表达式转义文本块中的所有特殊字符,是否有更简单的方法来做到这一点?
这背后的动机是将其附加到更大的正则表达式中,因此即使有更简单的方法来获得精确匹配,它们也不适用于此处。
我在 CentOS 机器上使用 Rstudio Server (0.98.490),它使用机器中的默认安装,它是旧版本的 R。我还在系统的其他地方编译了一个较新版本的 R。作为非 root 用户,我可以在开始会话时告诉 Rstudio 使用新安装而不是旧安装吗?
如果我有一个保存的图像文件,如何通过水管工为他们提供服务?
例如,这没有问题
# save this as testPlumb.R
library(magrittr)
library(ggplot2)
#* @get /test1
#* @png
test1 = function(){
p = data.frame(x=1,y= 1) %>% ggplot(aes(x=x,y=y)) + geom_point()
print(p)
}
Run Code Online (Sandbox Code Playgroud)
并运行
plum = plumber::plumb('testPlumb.R')
plum$run(port=8000)
Run Code Online (Sandbox Code Playgroud)
如果您访问http:// localhost:8000 / test1,则会看到正在提供的地块。
但是我找不到找到图像文件的方法
#* @get /test2
#* @png
test2 = function(){
p = data.frame(x=1,y= 1) %>% ggplot(aes(x=x,y=y)) + geom_point()
ggsave('file.png',p)
# code that modifies that file a little that doesn't matter here
# code that'll help me serve the file
}
Run Code Online (Sandbox Code Playgroud)
代替code that'll …
我有一个任意字符串,比如“1a2 2a1 3a2 10a5”
我可以相对轻松地提取我想要的数字
string = "1a2 2a1 3a2 10a5"
numbers = stringr::str_extract_all(string,'[0-9]+(?=a)')[[1]]
Run Code Online (Sandbox Code Playgroud)
显然,将它们加倍是微不足道的
numbers = 2*(as.integer(numbers))
Run Code Online (Sandbox Code Playgroud)
但是我在将新结果放在旧位置时遇到了问题。得到输出“2a2 4a1 6a2 20a5”。我觉得应该有一个单一的功能来完成这个,但我能想到的就是使用gregexpr
并手动将新结果记录在坐标中的匹配的原始索引。
我有一个字符串列表,我想应用一个方法(.split
).我知道这可以通过一个for
循环完成,但是知道python的心态我认为有更好的方法,比如map
函数
下面是我想用for
循环编写的东西
config = ['a b', 'c d']
configSplit = [None] * len(config)
for x in range(len(config)):
configSplit[x] = config[x].split()
configSplit
> [['a', 'b'], ['c', 'd']]
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我将使用insertUI
. 我试图找到一种方法来捕获这个模块的输出。在下面的应用程序中,有一个由textInput
元素组成的简单模块。服务器部分返回此textInput
元素的值并报告它处于活动状态。我正在尝试捕获此返回值。
我试图创建一个reactiveValues
对象来获取模块的输出,但是当输入改变时,这个对象似乎没有更新。模块代码本身正在运行,因为我收到来自模块内部的消息,但检查这些的外部观察命令reactiveValues
仅在重新创建时执行。如何从模块外部获取这些值
library(shiny)
# a module that only has a text input
moduleUI = function(id){
ns = NS(id)
tagList(
# the module is enclosed within a div with it's own id to allow it's removal
div(id = id,
textInput(ns('text'),label = 'text'))
)
}
# the module simply returns it's input and reports when there is a change
module = function(input,output,session){
observeEvent(input$text,{
print('module working')
})
return(input$text)
}
# ui is …
Run Code Online (Sandbox Code Playgroud)