Skip to content

Instantly share code, notes, and snippets.

@wush978
Last active December 14, 2015 04:38
Show Gist options
  • Save wush978/5029291 to your computer and use it in GitHub Desktop.
Save wush978/5029291 to your computer and use it in GitHub Desktop.
a <- "X123456789050102550703
A123456987050102660703
B123456789050102"
gregexpr("(?<id>[A-Z]\\d{9})(?<b_date>\\d{6})(?<d_date>\\d{6}){0,1}", a, perl=TRUE)
# [[1]]
# [1] 1 24 47
# attr(,"match.length")
# [1] 22 22 16
# attr(,"useBytes")
# [1] TRUE
# attr(,"capture.start")
# id b_date d_date
# [1,] 1 11 17
# [2,] 24 34 40
# [3,] 47 57 0
# attr(,"capture.length")
# id b_date d_date
# [1,] 10 6 6
# [2,] 10 6 6
# [3,] 10 6 0
# attr(,"capture.names")
# [1] "id" "b_date" "d_date"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment