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 Solution A regex a liner nth event The solution will use This is a solution that is Here is another solution using the If you want the NIT event user-defined , then you can use the following: _ :
[1] I think I want to split the second event of
_ : [1] "I like" "to_how_too"
strsplit with a single regex.
strsplit < Pre>
x <- "I like_to see_how_too" y
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"
n & lt; - 2 re & lt; --Paste0 ('(': (?: [^ _] * _) {', N,'}) (. *) '' Strepee (X, R, C, simple = sub ('_ $', '', X)) # [1] See "I like_to" "how_to"
Comments
Post a Comment