R中的字母数字正则表达式 [英] alphanumeric regular expression in R

查看:65
本文介绍了R中的字母数字正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 [:alnum:] ,如 ?regex 所述

I am trying to use [:alnum:] as explained on ?regex

谁知道为什么

grepl("^([a-zA-Z0-9])+([;])", x="dj5sads;adsa")

返回 TRUE,但

returns TRUE, but

grepl("^([:alnum:])+([;])", x="dj5sads;adsa")    

返回 FALSE?

推荐答案

[:alnum:] 只是类的名称.当你想把这个命名类放到一个字符类中时,你必须用另一对[]将它包围起来:

[:alnum:] is only the name of the class. As you want to put this named class into a character class, you have to enclose it with just another pair of []:

[[:alnum:]]

在你的例子中是

grepl("^([[:alnum:]])+([;])", x="dj5sads;adsa")    
//Output: TRUE

演示@ideone

这篇关于R中的字母数字正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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