Reputation: 4213
I am trying to use a regular expression for a message that has a temperature at the end of it. An example of a whole message looks like this:
RH= 12.1 %RH T= -3.5 'C
If it isn't obvious, the temperature (and part relevant to this question) is T = -3.5 'C
. I want to capture either C
or F
at the end. Right now I have this expression:
"RH=\\s*(?<1>[^\\s]*)\\s%RH T=\\s*(?<2>[^\\s]\\s*'\\w)"
But that will capture any alphanumeric character at the end. How do I change the last '\\w'
at the end to say, "only C
or F
?"?
Upvotes: 1
Views: 110
Reputation: 13672
Another alternative would be to replace the final \\w
with c|f
, meaning: either c or f.
Upvotes: 0
Reputation: 62266
Well, if provided formt is definitive, do not use complicated regex, but simple:
int index = data.LastIndexOf('\''); //index of last ' symbol
data.Substring(index);
Should workk for you.
Upvotes: 0