Why '[, - \\]' matches '46', 'X', 'A',

I am trying to break a string using strsplit(str, '[,-\\+]'), which means that anyone ',', '-' or '+'can be a delimiter. However, I found that this model also matches numbers and capital letters. Try

  • grep('[,-\\]', 'X'), returns 1
  • grep('[,-\\]', '46'), returns 1
  • grep('[,-\\]', '-'), returns 1
  • grep('[,-\\]', ','), returns 1

It seems to '[,-\\]'match all numbers, in capital letters, ','and '-'.

I just don’t understand why this is so.

Thanks for any input.

+4
source share
1 answer

You need to use

strsplit(str, '[,+-]')

to divide by , +or -. If you need to add \for separation, use the '[,\\+-]'default TRE with the regex mechanism.

- ( , ) , . , '[,-\\]' , \:

enter image description here

, TRE ( perl=TRUE), . "[,-\\]" , PCRE , 4 .

+3

Source: https://habr.com/ru/post/1682760/


All Articles