Capture values using regex
-
Hi I'm a Regex novice (very much learning as I go!) and I am trying to write a regex expression to capture the minimum and maximum temperature values in the string below. I'm hoping someone may be able to help e see where I have gone wrong?
class="outsideimage m0200006341e8" title="">
Humidity 100% Temp Min 3.1°C Temp Max 5.7°C
I have to include the m00006341e8 in the string to match as there are several other sensors that report in the overall text string and they all have a different serial number. I need to just extract the max and min values for this particular sensor. I think I've allowed for the fact that the humidity value may change I have tried the following, but it doesn't seem to be working: For the minimum temperature:
class="outsideimage m0200006341e8" title="">Humidity[0-9]*\%Temp Min([-]?[0-9]*[.]?[0-9]?)
and for the maximum temperature:
class="outsideimage m0200006341e8" title="">Humidity[0-9]*\%Temp Min[-]?[0-9]*[.]?[0-9]?°CTemp Max([-]?[0-9]*[.]?[0-9]?)°C
-
Hi I'm a Regex novice (very much learning as I go!) and I am trying to write a regex expression to capture the minimum and maximum temperature values in the string below. I'm hoping someone may be able to help e see where I have gone wrong?
class="outsideimage m0200006341e8" title="">
Humidity 100% Temp Min 3.1°C Temp Max 5.7°C
I have to include the m00006341e8 in the string to match as there are several other sensors that report in the overall text string and they all have a different serial number. I need to just extract the max and min values for this particular sensor. I think I've allowed for the fact that the humidity value may change I have tried the following, but it doesn't seem to be working: For the minimum temperature:
class="outsideimage m0200006341e8" title="">Humidity[0-9]*\%Temp Min([-]?[0-9]*[.]?[0-9]?)
and for the maximum temperature:
class="outsideimage m0200006341e8" title="">Humidity[0-9]*\%Temp Min[-]?[0-9]*[.]?[0-9]?°CTemp Max([-]?[0-9]*[.]?[0-9]?)°C
Don't try to use regular expressions to parse HTML. Use a library which is designed for the job instead. For example, in .NET you should use either AngleSharp[^] or Html Agility Pack[^]. You may also need to look at the surrounding HTML - based on the fragment you've shown, it's not clear whether the data from the other sensors is sufficiently separated from the data you're trying to extract.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Don't try to use regular expressions to parse HTML. Use a library which is designed for the job instead. For example, in .NET you should use either AngleSharp[^] or Html Agility Pack[^]. You may also need to look at the surrounding HTML - based on the fragment you've shown, it's not clear whether the data from the other sensors is sufficiently separated from the data you're trying to extract.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks Richard. Unfortunately, in the software I am using, I don't have an alternative and have to use Regex since that is all that is supported. I've since realised that it IS capturing the minimum temperature correctly, but it is not returning the Maximum temperature for some reason.
-
Thanks Richard. Unfortunately, in the software I am using, I don't have an alternative and have to use Regex since that is all that is supported. I've since realised that it IS capturing the minimum temperature correctly, but it is not returning the Maximum temperature for some reason.
Check the raw source of the string you're trying to match. It could be that the
°
character is actually°
,°
, or°
. Or it could be a different Unicode character entirely - for example:º
=º
/º
/º
˚
=˚
/˚
/˚
ᵒ
=ᵒ
/ᵒ
゜
=゜
/゜
ᣞ
=ᣞ
/ᣞ
⁰
=⁰
/⁰
Your minimum temperature regex doesn't try to match the character, but your maximum temp regex does.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer