I am looking for a regular expression to determine when any of the values in a 32-bit hex value is non-zero.
The data patterns look like 0x00000000 and I want to know when any of the digits is non-zero. For example, if 0x00001000 or 0x10000000 or 0xB000000 would be capture by the regular expression, but not a 0x00000000 pattern. Right now I perform a walking pattern match of
0x[^0] 0x0[^0] 0x00[^0] ... 0x0000000[^0]
This will work, but I much rather have one pattern if possible. Thanks.
Mark
Edit: I didn’t mention as the RegEx was not needed in a program, otherwise I would have used a different approach, but I was using the RegEx to search for values in a log file using UltraEdit. I could have developed a program or some other means to search, but I was just being lazy, just being honest. Ben S solution worked both in UltraEdit and Rad Software Regular Expression Designer. rampion solution didn’t work in either tool, not sure why.
Why not test the hex value against zero? Simpler, faster, more readable.
If a regular expressiong is really necessary,
0x0*[1-9a-fA-F][0-9a-fA-F]*should do it.It looks for as many zeros as it can until it finds a non-zero hex value, then gathers the rest of the hex regardless of if it’s a zero or not.
Note: this will match any length hex, not just 32 bits.