capturing
play

Capturing String Manipulation with stringr Capturing > ANY_CHAR - PowerPoint PPT Presentation

STRING MANIPULATION WITH STRINGR Capturing String Manipulation with stringr Capturing > ANY_CHAR %R% "a" <regex> .a > capture(ANY_CHAR) %R% "a" <regex> (.)a > str_extract(c("Fat",


  1. STRING MANIPULATION WITH STRINGR Capturing

  2. String Manipulation with stringr Capturing > ANY_CHAR %R% "a" <regex> .a > capture(ANY_CHAR) %R% "a" <regex> (.)a > str_extract(c("Fat", "cat"), pattern = ANY_CHAR %R% "a") [1] "Fa" "ca" > str_extract(c("Fat", "cat"), pattern = capture(ANY_CHAR) %R% "a") [1] "Fa" "ca"

  3. String Manipulation with stringr str_match() > str_match(c("Fat", "cat"), pattern = capture(ANY_CHAR) %R% "a") [,1] [,2] [1,] "Fa" "F" [2,] "ca" "c"

  4. String Manipulation with stringr str_match() > pattern <- DOLLAR %R% DGT %R% optional(DGT) %R% DOT %R% dgt(2) > str_view(c("$5.50", "$32.00"), pattern = pattern)

  5. String Manipulation with stringr str_match() > pattern <- DOLLAR %R% capture(DGT %R% optional(DGT)) %R% DOT %R% capture(dgt(2)) > str_match(c("$5.50", "$32.00"), pattern = pattern) [,1] [,2] [,3] [1,] "$5.50" "5" "50" [2,] "$32.00" "32" "00"

  6. String Manipulation with stringr Non-capturing groups > or("dog", "cat") <regex> (?:dog|cat) (dog|cat) dog|cat Need parentheses to distinguish do(g|c)at > or("dog", "cat", capture = TRUE) <regex> (dog|cat) > capture(or("dog", "cat")) <regex> ((?:dog|cat))

  7. STRING MANIPULATION WITH STRINGR Let’s practice!

  8. STRING MANIPULATION WITH STRINGR Backreferences

  9. String Manipulation with stringr Backreferences > REF1 <regex> \1 > REF2 <regex> \2

  10. String Manipulation with stringr In a pa � ern SPC %R% one_or_more(WRD) %R% SPC

  11. String Manipulation with stringr In a pa � ern SPC %R% capture(one_or_more(WRD)) %R% SPC

  12. String Manipulation with stringr In a pa � ern SPC %R% capture(one_or_more(WRD)) %R% SPC %R% REF1 > str_view("Paris in the the spring", SPC %R% capture(one_or_more(WRD)) %R% SPC %R% REF1)

  13. String Manipulation with stringr In a replacement > str_replace("Paris in the the spring", pattern = SPC %R% capture(one_or_more(WRD)) %R% SPC %R% REF1, replacement = str_c(" ", REF1)) [1] "Paris in the spring"

  14. STRING MANIPULATION WITH STRINGR Let’s practice!

  15. STRING MANIPULATION WITH STRINGR Unicode and pa � ern matching

  16. String Manipulation with stringr Unicode ● Associates each character with a code point Character Code Point a 61 3BC μ 😁 1F600

  17. String Manipulation with stringr Unicode in R > "\u03BC" [1] " μ " > "\U03BC" [1] " μ " > writeLines("\U0001F44F") 👐

  18. String Manipulation with stringr Unicode in R > as.hexmode(utf8ToInt("a")) [1] "61" > as.hexmode(utf8ToInt(" μ ")) [1] "3bc" > as.hexmode(utf8ToInt(" 😁 ")) [1] "1f600"

  19. String Manipulation with stringr Matching Unicode > x <- "Normal(\u03BC = 0, \u03C3 = 1)" > x [1] "Normal( μ = 0, σ = 1)" > str_view(x, pattern = "\u03BC") h � p://unicode.org/charts h � p://www.fileformat.info/info/unicode/char/search.htm

  20. String Manipulation with stringr Matching Unicode groups Use \p followed by {name} Regular expression rebus > str_view_all(x, greek_and_coptic()) ?Unicode ?unicode_property ?unicode_general_category

  21. STRING MANIPULATION WITH STRINGR Let’s practice!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend