I'm trying to write a string parser for a specific task and have made good progress, but one modification seems to cause problems I don't know how to solve. In the following, I need to pull out the " 89S" part and the following code does this:
In[]:=
StringCases[StringSplit["P225/50R16.0 89S", "/"][[2]],
RegularExpression["(\\d+)(R|D|B )(\\d+.?\\d*)(\\s\\d+\\D)"] :>
"$4"][[1]]
Out[]= " 89S"
But this last piece may or may not have parens around it. When I try to modify the above the allow for optional parens, it doesn't work. Any idea how to tweak the below to pull out the " (89S)" part?
In[]:=
StringCases[StringSplit["P225/50R16.0 (89S)", "/"][[2]],
RegularExpression[
"(\\d+)(R|D|B )(\\d+.?\\d*)(\\(?\\s\\d+\\D\\)?)"] :> "$4"][[1]]
During evaluation of In[]:= Part::partw: Part 1 of {} does not exist. >>
Out[]= {}[[1]]