0

I have a list of allowed characters:

alphanumerics and certain symbols: + - $

How can I check if my string contains only these?

For example, Avb@ should returm false, but dn$ should be TRUE.

Preferably, I would like to use base R only.

I have found posts on the same question for other languages, but not in R.

Thank you!

tzema
  • 451
  • 3
  • 11
  • 1
    You're looking for the so called regular expression: https://cran.r-project.org/web/packages/stringr/vignettes/regular-expressions.html – Davide Aug 18 '22 at 00:44
  • Closing this as a dupe; the linked post is an example demonstrating the use of regexp in R; you can find many more posts on the use of regexp's through the search. – Maurits Evers Aug 18 '22 at 00:50
  • I am not familiar with regexp. Is this the only way to go? – tzema Aug 18 '22 at 00:54
  • Based on the description of your problem, I'd say the answer is "yes". For example, `grepl` returns `TRUE`/`FALSE` for each matched element. – Maurits Evers Aug 18 '22 at 01:00

0 Answers0