新功能中的无效字符范围错误 [英] Invalid character range error in a new function

查看:103
本文介绍了新功能中的无效字符范围错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下错误消息有疑问

I have a problem with the follwoing error message


无效的正则表达式'([aZ] *)_(。*)' ,原因是无效字符范围

invalid regular expression '([a-Z]*)_(.*)', reason 'Invalid character range'

因此导致错误的代码行是

so the line of code which causes the error is

if(tide=="long") names(problem) <- sub("([a-Z]*)_(.*)","\\2",problem)

因此,如果在函数中的参数潮中选择了long,问题应该定义为..

so if long is selected for the parameter tide in the function the names of problem shall be defined ....

但是当我输入 function(...,tide = long,..)会显示上述错误消息。

but when I enter function(...,tide="long",..) the above mentioned error message is displayed.

推荐答案

您不能使用 [ aZ] ,因为字母顺序错误,但无论如何还是要使用以下字母:

You can't use [a-Z], because the letters are in the wrong order, but anyway it is better to use:

[a-zA-Z]

问题是这些范围是基于表的(两个ASCII或Unicode),但大写字母 Z位于小写字母 a之前,因此ra

The problem is that those ranges are based on tables (either ASCII or Unicode), but the uppercase letter "Z" comes before the lowercase letter "a" so the range is in the wrong order.

使用 [Az] 的另一个解决方案是有效范围,但是有字符

The other solution to use [A-z] would be a valid range, but there are the characters

[\]^_`

介于字母 Z和字母 a之间,因此该范围将包含您通常不希望匹配的字符。

between the letter "Z" and the letter "a", so this range would include characters that you normally don't want to match.

这篇关于新功能中的无效字符范围错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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