0

I would like to find the position of the following pattern: lower case letter followed by any character followed by any digit in the following string:

my_string <- "The current year is 2016"
my_pattern <- "[:lower:].[:digit:]"

library(stringr)
str_locate(my_string, my_pattern)
regexpr(my_pattern, my_string)

However get different results with str_locate (start 19) and regexpr (start 9)? Can anyone explain me why this happens?

R version 3.4.0 (2017-04-21) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS 10.13.1 stringr_1.2.0

Kev
  • 425
  • 3
  • 8
  • Just use the proper `"[[:lower:]].[[:digit:]]"` pattern. – Wiktor Stribiżew Dec 02 '17 at 11:59
  • Your right, however if someone does not know the expression POSIX character he or she won't find this question https://stackoverflow.com/questions/42013292/posix-character-class-does-not-work-in-base-r-regex – Kev Dec 02 '17 at 12:20

0 Answers0