R-lang /如何使用R进行正则表达式(Perl)提取 [英] R-lang / How to use R for regex (Perl) extraction

查看:94
本文介绍了R-lang /如何使用R进行正则表达式(Perl)提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript的正则表达式测试程序来提出以下3个正则表达式案例,从文本中提取不同类型的URL。我想在R中使用这些正则表达式(regexi?)来满足以下条件:

I used a regex tester for javascript to come up with the 3 following regex cases, to extract different types of URLs from text. I would like to use these regexs (regexi?) in R for these conditions:

http URL:(https?):\ / \\ \\ /(www \。)?[^ \\\\] +

http URL: (https?):\/\/(www\.)?[^\\s]+

网址: [ ^ https?:\ / \ /](bitly\.com | bit.ly)[^ \ s] +

www URL: \bwww \。[^ \ s] +

阅读正则表达式在R中,似乎使用 PERL = TRUE 将允许从javascript转换 - > RI在一些测试示例上尝试了我的上一个正则表达式:

Upon reading up on regex in R, it seems that using PERL=TRUE would allow for the conversion from javascript -> R.I tried my last regex on following on some test examples:

grep("\\<(\bwww\\.[^\\s]+)\\>", 
     c("wwww.google.com and other stuff", 
       "http.www.google.com"), 
     perl=TRUE, value=TRUE)

但我收到以下错误:


错误:grep(\<(\ bwww \。[^ \s] +)\>,
c(wwww.google.com和其他的东西, http.www.google.com)perl

Error: unexpected symbol in "grep("\<(\bwww\.[^\s]+)\>", c("wwww.google.com and other stuff", "http.www.google.com") perl"

在R中使用此类正则表达式的语法是什么?

What is the syntax for using this type of regular expression in R?

推荐答案


在R中使用这种类型的正则表达式的语法是什么?

What is the syntax for using this type of regular expression in R?

R参考索引,正则表达式:


Perl-like Regular Expressions



...

除了'\<'和'\>'之外,接受为扩展正则表达式
描述的所有正则表达式:在Perl中所有反斜杠
元字符是字母数字,反斜杠符号总是被
解释为文字字符。

Perl-like Regular Expressions


All the regular expressions described for extended regular expressions are accepted except ‘\<’ and ‘\>’: in Perl all backslashed metacharacters are alphanumeric and backslashed symbols always are interpreted as a literal character.

所以,如果你想使用 \< \> ,您不能使用 perl = TRUE

So, if you want to use \< \>, you must not use perl=TRUE.

此外这个,你忘了在 \b 中加倍反斜杠。

Besides this, you forgot to double the backslash in \b.

这篇关于R-lang /如何使用R进行正则表达式(Perl)提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆