Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I detect ¹ using stringr in R?

I would like to detect just ¹, ² etc in a string using stringr in R.

Later I’ll extract just it from a sentence (Like text¹ text, 2020)

library(stringr)

str_detect("¹", "[:digit:]")
#> [1] FALSE
str_detect("¹", "[:alpha:]")
#> [1] FALSE
str_detect("¹", "[:punct:]")
#> [1] FALSE

Created on 2022-11-19 with reprex v2.0.2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The patterns:

[⁰¹²³⁴⁵⁶⁷⁸⁹]+

or

\p{No}

will match superscript numbers (second option will also detect subscript so caution is advised, hence would recommend top)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading