regex - Split on first/nth occurrence of delimiter -


I'm trying to get what I thought would be easy. I am looking for a single RJX solution (though others have been welcomed to perfection). I want to divide the n frequencies of a delimiter

Strong> Negative results

says that I want to split the first event of _ :

  [1] I think I want to split the second event of  _ :   [1] "I like" "to_how_too"   

Solution A regex a liner nth event The solution will use strsplit with a single regex.

This is a solution that is strsplit < Pre> x <- "I like_to see_how_too" y

Here is another solution using the gsubfn package and some regex-fu. To change the nth event of the delimiter, you can swap the number that is placed inside the range quantifier ??? {n} .

  Library (GSUBFN) x & lt; - 'I like_View_Works' Strappe (X, '((?:: [^ _] * _) {1}) (. *)', C, simplify = sub ('_ $', '', x) ) # [1] "I like" "to_how_too"   

If you want the NIT event user-defined , then you can use the following:

  n & lt; - 2 re & lt; --Paste0 ('(': (?: [^ _] * _) {', N,'}) (. *) '' Strepee (X, R, C, simple = sub ('_ $', '', X)) # [1] See "I like_to" "how_to"    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -