Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204824

Given a multi-group pattern, how do you split a string on a specific group in that pattern?

$
0
0

I have this pattern that I want to use to split a vector: "([^ ])(,)([^ ])". But the vector should be split on the second group (,) leaving the first and the third with the first item and the second item respectively.

I tried to add the non-capturing pattern ?: but it doesn't seem to work.

my_string <- 
  "FIRST item,SECOND, item,third ITEM,FOURTH item"

strsplit(my_string, "(?:[^ ])(,)(?:[^ ])")[[1]]

I get "FIRST ite""ECOND, ite""hird ITE""OURTH item" will I need a pattern to get "FIRST item""SECOND, item""third ITEM""FOURTH item".


Viewing all articles
Browse latest Browse all 204824

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>