Yovanov
1
Hi!!
I have this problem: I know that "|" is used as OR, but I don´t know what the term is when I want to use the AND condition in stringr. What can I do?
str_detect(c('como', 'como-rer', 'cedcomo', 'ds-como'), '^como$|[como&-]')
TRUE TRUE TRUE TRUE
The result could be: TRUE TRUE FALSE TRUE
Thanks for your attention!!!!
lars
2
I modified your existing regex pattern so that it provides the outcome as expected. As you see, it still uses the OR-operator.
The 2nd example is finding words which matches on both conditions "starts with ds
AND after that contains rer
".
library(stringr)
## modified regex pattern with the OR-operator
str_detect(c("como", "como-rer", "cedcomo", "ds-como", "ds+como-rer"), "^como(?-)|(-como)")
#> [1] TRUE TRUE FALSE TRUE FALSE
## different pattern which states: word starts with 'ds' and then contains `rer` somewhere
str_detect(c("como", "como-rer", "cedcomo", "ds-como", "ds+como-rer"), "(^ds).+(rer)")
#> [1] FALSE FALSE FALSE FALSE TRUE
Created on 2021-02-19 by the reprex package (v1.0.0)
Hope this helps you forward.
1 Like
system
Closed
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.