regex - R grep to match dot -


so have 2 strings mylist<-c('claim', 'cl.bi'), when

grep('^cl\\.*', mylist) 

it returns both 1 , 2. if do

grep('^cl\\.', mylist) 

it return 2. why first match 'claim'? happened period matching?

"^cl\\.*" matches "claim" because * quantifier defined thusly (here quoting ?regex):

'*' preceding item matched 0 or more times. 

"claim" contains beginning of line, followed c, followed l, followed 0 (in case) or more dots, fulfilling requirements successful match.

if want match strings beginning cl., use one or more times quantifier, +, this:

grep('^cl\\.+', mylist, value=true) # [1] "cl.bi" 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -