A document to hold useful regular expressions that I have pulled together for things:
RegExr is a great and very handy online tool for checking regular expression matches: RegExr
+Nice addition for Stingray Application Firewall form field protection
So I have been trying to come up with a regex that would exclude lines with the word Fan and the include lines with temp in them (and without the word Fan)
When looking for assistance with Regex, it is very helpful to include sample text that you are looking to match and an idea of what platform / toolset you are running the regex match on.
I assume from your "temp" and "Fan" you are looking for a regex to give you temperatures from something, but don't want any Fan temperatures (ie: you want "CPU temp" and "Chassis temp", but not "Fan temp")
Regex gets tricky with exclusions. If your system doesn't need to be scaled to multiple gigabits of throughput (ie: doing the match in two operations won't break the CPU bank) you would probably be best to do this in two separate operations: first match "temp" then exclude lines that match "Fan" for example.
Most of the use cases I can think of for what you have asked are health checks as a shell script or scripting language (rather than using TrafficScript to parse HTML response data from a server, for instance)
Can you provide us with some sample data and an idea of what tool you are using to match this? If we can get that, we can be more helpful in suggesting a solution.
Hello eaengqu, I did not see which platform you are using - the best method might depend on the platform and throughput restrictions. As Aidan said above, you may find it easier (and more efficient) to run two separate test: first match "temp" - then exclude any of those lines which also include "Fan."
Alternatively, this single regex expression might work, depending on which platform you are using:
The regex matches any line with "temp" - where "Fan" does not appear before or after "temp" in the same line