问题
I have a problem with the follwoing error message
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)
so if long is selected for the parameter tide in the function the names of problem shall be defined ....
but when I enter function(...,tide="long",..)
the above mentioned error message is displayed.
回答1:
You can't use [a-Z]
, because the letters are in the wrong order, but anyway it is better to use:
[a-zA-Z]
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.
The other solution to use [A-z]
would be a valid range, but there are the characters
[\]^_`
between the letter "Z" and the letter "a", so this range would include characters that you normally don't want to match.
回答2:
Your problem is this [a-Z]
You have to write either : [a-z]
or [a-zA-Z]
来源:https://stackoverflow.com/questions/11966975/invalid-character-range-error-in-a-new-function