Pergunta

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?"?

Foi útil?

Solução

You can use a character class: instead of \\w, write [CF].

Outras dicas

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.

Another alternative would be to replace the final \\w with c|f, meaning: either c or f.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top