R regex to validate user input is correct.
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-03-16T00:29:14Z
Indexed on
2010/03/16
0:29 UTC
Read the original article
Hit count: 626
I'm trying to practice writing better code, so I wanted to validate my input sequence with regex to make sure that the first thing I get is a single letter A to H only, and the second is a number 1 to 12 only. I'm new to regex and not sure what the expression should look like. I'm also not sure what type of error R would throw if this is invalidated?
In Perl it would be something like this I think: =~ m/([A-M]?))/)
Here is what I have so far for R:
input_string = "A1"
first_well_row = unlist(strsplit(input_string, ""))[1] # get the letter out
first_well_col = unlist(strsplit(input_string, ""))[2] # get the number out
© Stack Overflow or respective owner