为什么gsub在Ubuntu上表现不同?

时间:2021-08-23 04:13:47

I wasn't able to test on all Linux distro, but gsub seems to behave differently when on Ubuntu :

我不能在所有的Linux发行版上进行测试,但是在Ubuntu上gsub的表现似乎有所不同:

url <- "http://thinkr.fr/"
gsub("(.*)/", "\\1", url) 

#Returns

# on mac, Windows, CentOS
[1] "http://thinkr.fr" 

# On Ubuntu (plain and Mint) 
[1] "http:/thinkr.fr" 

Ubuntu returns http:/ where all the others return http://.

Ubuntu返回http:/其他所有返回http://。

Any idea why?

知道为什么吗?

Here is the session info for the Linux Mint that produces the second output :

以下是Linux铸币厂的会话信息,用于生成第二个输出:

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18.2

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C               LC_TIME=fr_FR.UTF-8       
 [4] LC_COLLATE=fr_FR.UTF-8     LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8   
 [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] stringr_1.3.0 tidyr_0.8.0   dplyr_0.7.4   purrr_0.2.4   glue_1.2.0    attempt_0.2.0
[7] jsonlite_1.5  httr_1.3.1   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16     assertthat_0.2.0 R6_2.2.2         magrittr_1.5     pillar_1.2.1    
 [6] stringi_1.1.7    rlang_0.2.0      curl_3.0         neo4r_0.0.0.9000 bindrcpp_0.2    
[11] tools_3.4.3      igraph_1.2.1     yaml_2.1.17      compiler_3.4.3   pkgconfig_2.0.1 
[16] tidyselect_0.2.4 bindr_0.1        tibble_1.4.2

为什么gsub在Ubuntu上表现不同?

> extSoftVersion()
                               zlib                               bzlib 
                            "1.2.8"                "1.0.6, 6-Sept-2010" 
                                 xz                                PCRE 
                       "5.1.0alpha"                   "8.38 2015-11-23" 
                                ICU                                 TRE 
                                 ""           "TRE 0.8.0 R_fixes (BSD)" 
                              iconv                            readline 
                       "glibc 2.23"                               "6.3" 
                               BLAS 
"/usr/lib/libblas/libblas.so.3.6.0" 
> pcre_config()
             UTF-8 Unicode properties                JIT              stack 
              TRUE               TRUE               TRUE               TRUE 

1 个解决方案

#1


2  

In the image you uploaded showing your issue you don't have the "/" at the end of your string so it captures until the last "/" which is just the second slash in http://

在你上传的显示你的问题的图片中,你的字符串末尾没有“/”,所以它会捕捉到最后一个“/”,这只是http://中的第二个斜杠

So the issue is that you used a different input.

问题是你使用了不同的输入。

#1


2  

In the image you uploaded showing your issue you don't have the "/" at the end of your string so it captures until the last "/" which is just the second slash in http://

在你上传的显示你的问题的图片中,你的字符串末尾没有“/”,所以它会捕捉到最后一个“/”,这只是http://中的第二个斜杠

So the issue is that you used a different input.

问题是你使用了不同的输入。