Search code examples
c#regexor-operator

OR expression in regular expression?


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


Solution

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