rregexstringicharacter-class

Exclude "I" and "O" from alpha-numeric id in stringi character set


I know from Generate unique alphanumeric IDs, that I can use stringi and stri_rand_strings to generate a unique alpha-numeric id. I am trying to figure out an efficient way to do so but only include the numbers 0-9 and all letters but "I" and "O". I can't seem to figure out how to include this in the pattern c( LETTERS[c(1:8,10:14,16:26)],"[0-9]")

stri_rand_strings(25, 6)

Solution

  • Modify the pattern to exclude those letters

    stri_rand_strings(25, 6, pattern = "[a-zA-HJ-NP-Z0-9]")
    
    [1] "l3e6eH" "NfcjuP" "vtHxWy" "bs2Zd1" "2UGWoJ" "GhettL" "mvvLqi" "AtBBnd" "ijsDFj" "4CXpn6" "MpyUEh" "HZUyDi" "Fba7Af"
    [14] "M3lWdn" "A5Vf8D" "tcC9as" "jTXyK5" "U5gUCy" "rnQN1p" "vEouUF" "c8ZU35" "C91o7m" "vuM7iE" "dl49kM" "opucvl"
    

    To only use capital letters

    stri_rand_strings(25, 6, pattern = "[A-HJ-NP-Z0-9]")