A convenience function for the perl = TRUE patterns for "(?<=[a-zA-Z])(?=[0-9])" and "(?<=[0-9])(?=[a-zA-Z])". That's it. Really.

CharNumSplit(string, alphaFirst = TRUE)

Arguments

string

The string to be split.

alphaFirst

Logical. Characters first (TRUE)? Or numbers (FALSE)?

Value

A list with the split values.

References

http://stackoverflow.com/a/23052016/1270695

Author

Ananda Mahto

Examples

STR1 <- c("ABC123", "BCD234", "CDE345", "DEF456") STR2 <- c("123ABC", "234BCD", "345CDE", "456DEF") CharNumSplit(STR1, alphaFirst = TRUE)
#> [[1]] #> [1] "ABC" "123" #> #> [[2]] #> [1] "BCD" "234" #> #> [[3]] #> [1] "CDE" "345" #> #> [[4]] #> [1] "DEF" "456" #>
CharNumSplit(STR2, alphaFirst = FALSE)
#> [[1]] #> [1] "123" "ABC" #> #> [[2]] #> [1] "234" "BCD" #> #> [[3]] #> [1] "345" "CDE" #> #> [[4]] #> [1] "456" "DEF" #>