Closed andkov closed 6 years ago
@andkov, I assume this is in R? If you start the R code (like put the subject in an array), I'll use that next time. Those options (eg, 'gm') might need to be modified if you're matching in R. I'd need to see if each line was its own element in an array. Or if this whole block was in a single element.
pattern 1a: ^\s*(\w{2,4})\s*-?\s*(\d{2,3})?$
pattern 1b: ^\s*(\w{2,4})\s*-?\s*(|\d{2,3})$
substitution: [\1]-{\2}
@wibeasley , just FYI. I"m collecting bits and pieces.
Given the subject
compose a regex that would separate the two components of the complex string, but also would match strings that do not have a numeric qualifier (
BC
). In other words, make the second capturing group optional.To get you startered at regex101.com: